Author Topic: random range fail  (Read 1706 times)

0 Members and 1 Guest are viewing this topic.

Offline lewymati

  • Major(1)
  • Posts: 38
random range fail
« on: July 23, 2008, 05:39:36 am »
meh... Ive just done some testing with random function:

Code: [Select]
procedure AppOnIdle(Ticks: integer);
begin
   WriteConsole(0,inttostr(random(1,2)),$EE81FAA1);
end;
returns only 1

Code: [Select]
procedure AppOnIdle(Ticks: integer);
begin
   WriteConsole(0,inttostr(random(1,3)),$EE81FAA1);
end;
returns randomly 1 or 2


so random definition: random(minimum,maxium) kinda fail
its now <minimum;maximum)
will it be changed?

Offline As de Espada

  • Soldat Beta Team
  • Veteran
  • ******
  • Posts: 1493
  • Mapper
    • My maps
Re: random range fail
« Reply #1 on: July 23, 2008, 02:59:26 pm »
the maximum will never be reached
just make sure you remember that
All my maps | my latest map: SoldatX Racing Mappack
me making a map on youtube: ctf_FastMade

Offline lewymati

  • Major(1)
  • Posts: 38
Re: random range fail
« Reply #2 on: July 23, 2008, 03:16:34 pm »
so thats okay?

imho maximum value is value which should be reached...

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: random range fail
« Reply #3 on: July 23, 2008, 03:29:06 pm »
its maximum exclusive I guess. just add 1 to whatever you want it to be and you'llbe fine.

Offline lewymati

  • Major(1)
  • Posts: 38
Re: random range fail
« Reply #4 on: July 24, 2008, 03:30:34 am »
its maximum exclusive I guess. just add 1 to whatever you want it to be and you'llbe fine.

guys... I know that, but i won't be fine. I meant that in formal point of view its bad. Ofc script will work now with that added 1, but what when in some neuer soldat server version it will be changed?
Imho script language have to has clear documentation and every thing have to be done right as in documentation is written.
I just want to know if my script with that added 1 will work in next versions. That's why i started that topic...

Offline Neosano

  • Camper
  • ***
  • Posts: 253
  • IIAWAK!
Re: random range fail
« Reply #5 on: July 24, 2008, 04:54:54 am »
Imho script language have to has clear documentation and every thing have to be done right
Learn pascal then?
KAWAAAAAAAIIIIIIIIII

Offline chutem

  • Veteran
  • *****
  • Posts: 1119
Re: random range fail
« Reply #6 on: July 24, 2008, 05:05:05 am »
That particular function probably isn't related to pascal itself, I think it was an error by EnEsCe, and that it is supposed to include the maximum number.
1NK3FbdNtH6jNH4dc1fzuvd4ruVdMQABvs

Offline lewymati

  • Major(1)
  • Posts: 38
Re: random range fail
« Reply #7 on: July 24, 2008, 05:39:19 am »
Learn pascal then?

god damn you? Learn pascal yourself... I was writing in pascal for 5 years(now im writing mostly in C++, im using pascal now in soldat scripting and writing my own game in Delphi), and there was a random() function only with one parameter. It is: random(range:integer) and it returns numbers from 0 to range-1
But probably EnEsCe overloaded that random with his own one, and probably as chutem said he made an error. Idk that rly why he changed that, old random was quiet good.

Offline sai`ke

  • Camper
  • ***
  • Posts: 318
  • Can't be arsed to remove christmas avatar
Re: random range fail
« Reply #8 on: July 24, 2008, 07:07:42 am »
Code: [Select]
function rnd( min, max: integer ): integer;
begin
result := random( min, max+1 );
end;
Use that. Problem solved. If they ever change the random command, you just change the routine and everything is changed appropriately.
#soldat.ttw #ttw.gather --- Quakenet!
http://ttwforums.com

Offline Neosano

  • Camper
  • ***
  • Posts: 253
  • IIAWAK!
Re: random range fail
« Reply #9 on: July 24, 2008, 10:40:47 am »
2Lewymati

http://www.learn-programming.za.net/programming_pascal_learn04.html

Scroll down - EXTRAS:
Quote
The Random command will give you a random number from 0 to the number you give it - 1. The Random command generates the same random numbers every time you run a program so the Randomize command is used to make them more random by using the system clock.
KAWAAAAAAAIIIIIIIIII

Offline lewymati

  • Major(1)
  • Posts: 38
Re: random range fail
« Reply #10 on: July 24, 2008, 10:58:30 am »
Learn pascal then?

god damn you? Learn pascal yourself... I was writing in pascal for 5 years(now im writing mostly in C++, im using pascal now in soldat scripting and writing my own game in Delphi), and there was a random() function only with one parameter. It is: random(range:integer) and it returns numbers from 0 to range-1
But probably EnEsCe overloaded that random with his own one, and probably as chutem said he made an error. Idk that rly why he changed that, old random was quiet good.


2Lewymati

http://www.learn-programming.za.net/programming_pascal_learn04.html

Scroll down - EXTRAS:
Quote
The Random command will give you a random number from 0 to the number you give it - 1. The Random command generates the same random numbers every time you run a program so the Randomize command is used to make them more random by using the system clock.

gtfo man, learn2read first

Code: [Select]
function rnd( min, max: integer ): integer;
begin
result := random( min, max+1 );
end;
Use that. Problem solved. If they ever change the random command, you just change the routine and everything is changed appropriately.

Meh, thats still need changing it later... A little but still....

At least I can write my own random function which will take numbers for ex. from date :P

Offline As de Espada

  • Soldat Beta Team
  • Veteran
  • ******
  • Posts: 1493
  • Mapper
    • My maps
Re: random range fail
« Reply #11 on: July 24, 2008, 01:46:43 pm »
the original random already goes to the range-1, maybe that's the logic that enesce used... min to max-1. And I think that this function will never be changed, to maintain compatibility between versions.
All my maps | my latest map: SoldatX Racing Mappack
me making a map on youtube: ctf_FastMade

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: random range fail
« Reply #12 on: July 24, 2008, 06:27:06 pm »
umm... actually after a bit of research it turns out that it's standard for it to go from 0 inclusive to the number you provide exclusive. In other programming languages I mean. but honestly... do we really care?