View Full Version : rand command is not random!

10 October 2006, 03:28 PM

i got a problem with the mel random commands. each time i restart maya it returns the same "random" numbers!
i just start maya and type "rand 100" in the script editor, i get the same numbers like 17, 71, 61, 28, 56....
i tried the same with maya 7.0 and 6.5 on different machines, it's the same! what did i forget?


10 October 2006, 04:35 PM
you should initialize the random number generator with a value which is different every time maya is started - like the current time (i actually don't know how to get that). then you'll get different values.
this is done by the seed command.

10 October 2006, 04:35 PM
what happens when you write:


10 October 2006, 05:13 PM
thx for reply, first of all, it's the same with the "rand(0,100);", it doesn't matter.
sure, i can initialize every time after start a new sequence of random numbers with the seed command and a different value for it.
the problem is, i use a script for random selection and after a new start of maya the "random" selection was the same.
Is it really usual, that the random commands have to be reinitialized after restart of maya if i need really different random values? with java or C i get "real" randomness, why not with maya?
Does anybody know, how the random commands work, just for my interest ;-)!

10 October 2006, 06:30 PM
You didn't forget anything.

Your computer can't generate truly random numbers, it's a "flaw" with the construction. You can get special (expensive) hardware that will generate a truly random number if it's that important. The easiest way to acheive the appearance of randomness is to use the seed() function as someone mentioned earlier. Use the about -ct command to get the current time and then you can tokenize that for a usable value.

Hope this helps.

10 October 2006, 01:59 PM
i got it now, in deed, i had to initialize seed with randon numbers, i used the seconds of the actual system time!

thanks for helping!!!

CGTalk Moderation
10 October 2006, 01:59 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.