Reputation: 3718
This is a language agnostic question. I'm curious if it's possible to generate a pseudo-random number without: 1. Using the language's builtin/stdlib random functions 2. Using the current time. 3. Getting assistance from the OS, i.e. reading from /dev/random on *nix platforms.
I realize these are some far-out artificial constraints. Also, I want to point out that I'm not concerned about how properly random the result is. Seemingly random would be good enough for the purpose of this question. It's not for cryptographic application.
Upvotes: 0
Views: 208
Reputation: 12978
There are plenty of algorithms for generating pseudo-random numbers that can be implemented without using built in random functions etc.
E.g. (from Wikipedia):
An example of a simple pseudo-random number generator is the multiply-with-carry method invented by George Marsaglia. It is computationally fast and has good (albeit not cryptographically strong) randomness properties:
m_w = <choose-initializer>; /* must not be zero, nor 0x464fffff */
m_z = <choose-initializer>; /* must not be zero, nor 0x9068ffff */
uint get_random()
{
m_z = 36969 * (m_z & 65535) + (m_z >> 16);
m_w = 18000 * (m_w & 65535) + (m_w >> 16);
return (m_z << 16) + m_w; /* 32-bit result */
}
If you don't want to use the clock as the source of your random seed, you could make it a function of the state of your machine (e.g. some hash of memory state).
Upvotes: 1