Sign in to follow this  
Followers 0
Guest fractal54

Random() clarification

3 posts in this topic

hi i'm new to AutoIt though i've accomplished a lot already in a script i'm writing. I just need clarification on the definition of the Random function. According to the documentation, it's pseudo-random. And yet when i use it to test my script, it's acting like it's "really" Random (as in, it takes in the computer time as the seed).

In any case, is there a way for me to enter my own seed?

Thanks!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Computers can't generate random numbers because they can't think.

So humans invented programs to allow the computers making calculated numbers, but that are almost randoms since based on many factors that are very difficut to guess.

The easiest way I know is using as dividend the milliseconds of time passed from last boot and as divisor the max number you are looking for + 1, the modulus is your 'Random' number.

As you can see, it is not actually 'Random', but considering how fast milliseconds passes and ignoring when you cast your script the effect is the same.

Do you see now?

Edited by ezzetabi

Share this post


Link to post
Share on other sites

Thanks. I suppose i should've been clearer with my question. I do know that computers can't generate a truly random number (nor can they detect a possible infinite loop in a code before compilation).

It's just that in my experiences with programming languages, random functions have always come in 2 main flavors: "pseudo-random" -- that which takes in a user-given seed, and random -- that which takes in time as a factor in a seed automatically. Kinda like rnd() and rand() in C++ (if i recall correctly).

In any case, i think i've known the answer all along. But you have confirmed it for me. Much to my disappointment, however, to discover that the Random function in autoit CANNOT accept user-given seeds. It would've been very helpful to debug my script.

Thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0