Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Randint Not so random?
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Archi




PostPosted: Thu Jul 10, 2003 9:58 am   Post subject: Randint Not so random?

I've done quite a few tests on this and I've found that the randint function likes to pick large numbers rather than small numbers. Is there a way to make it chose more smaller numbers than large?? or is it just screwed up?
Sponsor
Sponsor
Sponsor
sponsor
krishon




PostPosted: Thu Jul 10, 2003 10:25 am   Post subject: (No subject)

well its just random...i dunno...unless u want to lower the range...
rizzix




PostPosted: Thu Jul 10, 2003 11:17 am   Post subject: (No subject)

i wonder how they implemented this random function..
if it is based on some funny math.. it is not random .. and they did a terrible job.. otherwise they did a terrible job... o well Rolling Eyes
Homer_simpson




PostPosted: Thu Jul 10, 2003 2:40 pm   Post subject: (No subject)

i believe it works by getting the system time and doing some "funny math" on it...
Tony




PostPosted: Thu Jul 10, 2003 3:54 pm   Post subject: (No subject)

it is... it seeds the function with system time and does "funny" math to get a number in between the specified range. So techincally you're more likely to get a sertain number at sertain time of the hour.

although I think that consequtive picks are seeded with result from the last run of the function (or they just seed with systemtime + milliseconds) since I remember that in v3 you used to get the same random number untill the second was over.

Ether way, there is no fuction to produce a truly random number, although they fake it quite well (apparently, not well enough)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
AsianSensation




PostPosted: Thu Jul 10, 2003 6:23 pm   Post subject: (No subject)

yeah, tony's right, the thing is based on time...

code:

put Rand.Int (1,100)


press F1 like crazy, you'll see that you get the same answer for a while, then it changes, weird eh?

You would think that "Random" means random, but apparently, "Random" is based on time...
Catalyst




PostPosted: Thu Jul 10, 2003 7:06 pm   Post subject: (No subject)

using time is one of the only ways to generate pseudo-random numbers effectiely
Tony




PostPosted: Thu Jul 10, 2003 7:38 pm   Post subject: (No subject)

well time is usually used as a seed for the function, although that number could come from any other source that frequently changes in value. That being said, if the first seed comes from time and sequential seeds come from result of the previous random function (as a lot of programs do out there), then it is in fact possible to have a list of all the random numbers generated available before they happen if you start the program at the exact second Shocked (or just freeze your system clock, ether way)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Dan




PostPosted: Thu Jul 10, 2003 7:41 pm   Post subject: (No subject)

Catalyst wrote:
using time is one of the only ways to generate pseudo-random numbers effectiely


ture, but this only gets the random seeds for the numbers, there is a standred mathmatic equaction to make pseudo-random numbers.

here is the stander mathical equation for pseudorandom numbers:

next = next * 1103515245 + 12345
rannum = (next/65536) % maxrannum

this gives you pseudorandom numbers but will all ways be the same numbers, thats why you need a random seed to keep the number sets difrent.

a seed is sipely the starting value of next.

most randomly grentated numbers are realted to system time b/c it is the strating value of next. also the number of rannum is ushley rounded or just the decmales cut off for ints.

and thats how it is done Wink

Edit: this was posted b4 i saw tonys post. dam you beat me Evil or Very Mad
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
rizzix




PostPosted: Thu Jul 10, 2003 8:01 pm   Post subject: (No subject)

now-a-days it is prefered to gather ethropy fomr keyboard / mouse movements etc.. its much much better than using the system time.

i know for a fact advanced encryption applications use it. (i use one all the time... try PGP.. or GPG.. reall fun.. i think all compsci member should have such an application installed [for windows just go for PGP] ... not just because of the "super duper top secret stuff we do here", but it's fun!)
Dan




PostPosted: Thu Jul 10, 2003 8:20 pm   Post subject: (No subject)

i whould just like to add that i dont think turing uses that foraml b/c it whould over flow if the ranum number was biger then 2. this is due to turing only using a max of 4 beyts to make int, nat, real, and other varibales.

i do think this is how c at least used to do it.

aslo for poleop who dont know the % is the same as mod fuction in turing
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
SilverSprite




PostPosted: Thu Jul 10, 2003 8:39 pm   Post subject: (No subject)

AsianSensation wrote:
yeah, tony's right, the thing is based on time...

code:

put Rand.Int (1,100)


press F1 like crazy, you'll see that you get the same answer for a while, then it changes, weird eh?

You would think that "Random" means random, but apparently, "Random" is based on time...

If you can come up with a better random that means random then by all means.. but this is good enough for now.. anyways yeah random is based on time but hm i know that you can change the seed in c++ i think that in turing the keyword randomize does the equivalent.. but it slows the program down alot!
Mazer




PostPosted: Thu Jul 10, 2003 8:52 pm   Post subject: (No subject)

just a second kiddies. Wink

edit:
damnit all, i just wrote this big ass paragraph explaining the random numbers in turing and just noticed it's already been explained twice. Evil or Very Mad Evil or Very Mad

damn you all. well, not all of you.
SilverSprite




PostPosted: Thu Jul 10, 2003 8:57 pm   Post subject: (No subject)

well this thread started a long time ago .. you must be real slow
AsianSensation




PostPosted: Thu Jul 10, 2003 9:00 pm   Post subject: (No subject)

what exactly does Randomize do in turing? I've heard that they made it obsolete, and it has no use in the newer version (4.0.some letter)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 22 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: