Re: Seeding the pseudorandom number generator



chase321 wrote:


Hal Ashburner-2 wrote:
chase321 wrote:
I have been using Gnumeric for some time in the statistics classes I
teach. 
This past semester, I did my first online section, and had them submit
labs
using Gnumeric.  For one lab, I had them use the "randbetween" function
to
generate random numbers.  9 of the 17 labs I received had identical sets
of
random numbers.  This makes me more than a little suspicious, but I have
also seen students get the same sequence of numbers in the classroom.  I
know enough about pseudorandom number generators to know that if two
people
start at the same point in the sequence, they're going to get the same 
set
of numbers.  So I have two questions.
1) How is the pseudorandom number generator initialized (seeded)?
2) Is there any way to seed it manually?  I can find no function for this
mentioned in the manual.

Thanks for any help.
Hi Chase,
Looking at the code in plugins/fn-random/functions.c and src/mathfunc.c
it appears rand_01 is the relevant function. By setting the environment
variable GNUMERIC_PRNG_SEED
(on unix with a bourne compatible shell with something like
$ export GNUMERIC_PRNG_SEED=some_random_string
) will cause rand_01 to use a pseudo random number generator using the
specified seed. Otherwise it should get its random numbers from
/dev/urandom

My understanding of this is that if GNUMERIC_PRNG_SEED is set then each
time you open a sheet containing randbetween you will get the same
value, whereas if it isn't then you won't.

Are you using windows by any chance?

Kind regards,
Hal


I'm using Linux, but most if not all of my students are using Windows. 
What I actually had them do is generate the random numbers and then copy
and paste "as value" so the numbers would stay fixed for the rest of the
activity.  So I should be getting the actual numbers that they got.  Of
course, if one of them did the lab and then passed the finished product
around to the others, that would certainly explain it, but I don't want to
claim that if I'm not sure. 
Would the Windows installer set the environmental variable?  I can check
tomorrow to see if it's set on my Windows machine at the office.
Incidentally, grades are already in, so I won't be taking this to the dean
at this point, but  I would like to know what's going on.
Thanks for the quick reply!

Shame on you for having such a suspicious mind with respect your
students! :)
In this case I strongly suspect based on the relevant gnumeric code that
those students with the same randomly generated values are not cheating.
(And on prejudice, in my experience students aren't quite so stupid when
they are cheating. Academic misconduct is certainly more common than it
ought to be, seemingly as much among faculty as the student body.)

If the environment variable is not set, then gnumeric tries to get
values from /dev/urandom, this is obviously not something that is
available on windows and I can't see anything in the code that does
whatever is equivalent for windows. It just tries to open the file
specified by the hardcodes string /dev/urandom and falls back to
pseudorandom if it fails, rather than using something like that which is
documented here:
http://blogs.msdn.com/michael_howard/archive/2005/01/14/353379.aspx
I'm not terribly near a windows computer to test this. If you are near a
windows computer with gnumeric installed, just create a sheet with
=randbetween(1,1000) or similar in it somewhere and open then close it
several times seeing if you always get the same value in the cell. I
strongly suspect you will.

It appears there is no open bug for this, so I've opened one here:
http://bugzilla.gnome.org/show_bug.cgi?id=533779
This isn't code I know at all well, so if someone clues me up that I'm
being stupid, I'd be grateful.

Kind regards,
Hal Ashburner



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]