Re: What is best way to set_rand?
- Posted by DerekParnell (admin) Jan 24, 2013
- 1307 views
I want to use two values as seeds for set_rand. How many bit these values have in width? What is best way to use hashes (of external data) as seeds?
There is no best way. It all depends on what you are trying to achieve.
The purpose of set_rand() is ensure that the next set of random numbers generated by the library are able to be repeated. That is to say, you call set_rand() before a series of calls to generate random numbers, so that the set you get is always the same set.
If you actually want the next set of generated random numbers to be unpredictable, call set_rand() with an empty sequence. Every other way of calling set_rand() will make the next set of numbers predictable in the sense that the set will be able to be repeated. The parameters given to set_rand() merely dictate which set of random numbers will be generated next.
It doesn't matter that much what you use to define the next set of random numbers, so using any algorithm in hash() to create some seeds would be just as good as any other algorithm.
For example ...
include std/rand.e sequence S,T set_rand("test") S = {} for i = 1 to 10 do S &= rand(100) end for set_rand("test") T = {} for i = 1 to 10 do T &= rand(100) end for ? equal(S,T) --> 1 (Both sets are identical) set_rand("") S = {} for i = 1 to 10 do S &= rand(100) end for set_rand("") T = {} for i = 1 to 10 do T &= rand(100) end for ? equal(S,T) --> 0 (Both sets are different)