How to force GAP give me a true random number

gaprandom

I am using GAP (see https://www.gap-system.org/) in a number theory class to display a variety of number theoretic functions and number theory problems. I've written code in GAP to implement the RSA encryption scheme but unfortunately, the random number generation I am using (x := Random([1..10^18]); ) gives every student the same random number! The goal is for each student to generate two random primes of a certain length and use them in their RSA encryption. This is, of course, defeated if we all get the same "random" number!

How do I force GAP to choose something truly random, something that cannot be duplicated by another student?

Best Answer

The default in GAP is that the random number generator always initializes with the same seed to make calculations reproducible.

One could use e.g. CurrentDateTimeString to re-seed the default random number generator with a changing initial value that is unlikely to be the same for two students, if they work unsynchronized.

Reset(GlobalMersenneTwister,CurrentDateTimeString());;

While this is probably not good enough for military grade cryptography, it should scramble sufficiently for classroom purposes.

Related Question