![]() |
2011-08-01
, 05:22
|
|
Posts: 4,672 |
Thanked: 5,455 times |
Joined on Jul 2008
@ Springfield, MA, USA
|
#2
|
So as part of a fancy shellscript I'm making, I need to generate a random number that will accept a custom seed value, and output a "random" number within a custom range starting from 0. But that random number needs to be totally predictable based on the seed, so that if I run the script on another machine with the same inputs it'll get the same result. I've tried this:
...but I'm getting different results on different PCs. On one PC the results are predictable but something here is accepting a seed other than $seedvalue that varies from one PC to the next.Code:awk 'BEGIN { srand($seedvalue); printf("%d\n",rand()*$max)
The script can only use standard GNU tools included on even minimalistic distros.
Any ideas?
![]() |
2011-08-01
, 05:50
|
Posts: 2,802 |
Thanked: 4,491 times |
Joined on Nov 2007
|
#3
|
The script can only use standard GNU tools included on even minimalistic distros.
![]() |
2011-08-01
, 07:33
|
Posts: 1,680 |
Thanked: 3,685 times |
Joined on Jan 2011
|
#4
|
...But that random number needs to be totally predictable based on the seed...
![]() |
2011-08-01
, 13:08
|
Posts: 692 |
Thanked: 264 times |
Joined on Dec 2009
|
#5
|
![]() |
2011-08-01
, 14:43
|
Posts: 692 |
Thanked: 264 times |
Joined on Dec 2009
|
#6
|
python -c "exec(\"import random; random.seed(999); x=random.randint(0,10); print x;\")" | tr -d '\n'
The script can only use standard GNU tools included on even minimalistic distros.
Any ideas?
"Impossible is not in the Maemo vocabulary" - Caballero