Quote:

and why would you seed a RND



You need to seed it because it is a pseudo-random number generator, not a random number generator.

The RNG (random number generator) works by taking a start value, pushing it through a complex calculation and ending up with another number. The problem is that first number. There is absolutely no random event that your PC can get to to establish that first number.

This means that it is up to you to find a random-ish number.

The other reason for having a seed is that a predictable stream of "random" number might be desirable. You might want to get the same numbers every time you run the program.

I use this for password generation. The BIOS on our PCs is locked down with a password. Unfortunately somtimes we need to divulge this password to employees or third party engineers so we cannot use a common password.

We could allocate random passwords and record them on a spreadsheet, but that would be an administrative nightmare.

Instead we generate random passwords using a hash of the PC serial number as a seed. This means we can always regenerate the password by typing the PC serial number into the password program.

The local administrator password is managed in the same way.

Quote:

Re: RND

so if I am using RND to generate a number in an UDF, will it generate the same RND each time I call the UDF, or will it generate the same RND each time I run the script?




The RNG state is in the KiXtart session scope. This means that you only need to seed the RNG once per kix32.exe execution.

Even if you run a number of scripts e.g. "kix32.exe script1.kix script2.kix script3.kix" you will only need to seed the RNG in script1.kix

The RNG is pretty basic, and one of it's flaws is that the first number returned is not very random at all. It is good practice to discard the first number after seeding the RNG.

Also, don't seed the RNG in the UDF as that will restart the pseudo-RNG sequence making it even less random!

Finally, don't used @MSECS alone to seed the RNG. Choose something else. @MSECS has a range of 0-999 which means that your "random" numbers will only be from a selection of a thousand possible results. We are moving from random numbers towards predictable!

@TICKS is a better option for a simple seed. A reasonable (if not perfect) simple seed might be:
Code:
SRND(@TICKS*1000+@MSECS)