[Bug 804355] [NEW] jot random number generator broken in batch jobs

Launchpad Bug Tracker 804355 at bugs.launchpad.net
Thu Mar 15 16:13:34 UTC 2012


You have been subscribed to a public bug by Ubuntu Foundation's Bug Bot (crichton):

jot -r generates same random numbers within one second time so it's
unusable in batch jobs like shell scripts.

There is code for initializing "random" seed:
    s = (randomize ? time(0) : STEP_DEF);
    /*... snip ....*/
    srand((int) s);

Here is an example of this behavior:
rbtz at rbtz-desktop:~$ date +%s; jot -r 1 0 10000000
1309455778
9981995
rbtz at rbtz-desktop:~$ date +%s; jot -r 1 0 10000000
1309455779
2355993
rbtz at rbtz-desktop:~$ date +%s; jot -r 1 0 10000000
1309455779
2355993
rbtz at rbtz-desktop:~$ date +%s; jot -r 1 0 10000000
1309455779
2355993
rbtz at rbtz-desktop:~$ date +%s; jot -r 1 0 10000000
1309455780
3745306
rbtz at rbtz-desktop:~$ date +%s; jot -r 1 0 10000000
1309455780
3745306

As fast fix pid can be added to seed
srandom((int) s ^ (getpid()<<4));

As good fix arc4random or similar mechanism can be used.

** Affects: athena-jot (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: patch
-- 
jot random number generator broken in batch jobs
https://bugs.launchpad.net/bugs/804355
You received this bug notification because you are a member of Ubuntu Sponsors Team, which is subscribed to the bug report.



More information about the Ubuntu-sponsors mailing list