Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulating /dev/random on Windows

I'm trying to port python code from linux to windows right now. In various places random numbers are generateted by reading from /dev/random. Is there a way to simulate /dev/random on Windows?

I'm looking for a solution that would keep the code useable on linux...

like image 550
scherlock Avatar asked Jun 06 '12 11:06

scherlock


People also ask

How is Dev random generated?

/dev/random uses an entropy pool of 4096 bits (512 Bytes) to generate random data and stops when the pool is exhausted until it gets (slowly) refilled. /dev/random is designed for generating cryptographic keys (e.g. SSL, SSH, dm-crypt's LUKS), but it is impractical to use for wiping current HDD capacities: what makes ...

Does Windows have dev random?

Cygwin on Windows provides implementations of both /dev/random and /dev/urandom, which can be used in scripts and programs.

Is Dev urandom random?

The /dev/urandom device provides a reliable source of random output, however the output will not be generated from an equal amount of random input if insufficient input is available.

What is the difference between Dev random and Dev urandom?

The key difference between /dev/random versus /dev/urandom is whether a threshold of enough entropy has to be reached before random numbers are generated. Reading from /dev/random will be put on hold if the kernel has not gathered enough entropy to provide the requested amount of data.


3 Answers

If you are using Python, why do you care about the specific implementation? Just use the random module and let it deal with it.

Beyond that, (if you can't rely on software state) os.urandom provides os-based random values:

On a UNIX-like system this will query /dev/urandom, and on Windows it will use CryptGenRandom.

(Note that random.SystemRandom provides a nice interface for this).

If you are really serious about it being cryptographically random, you might want to check out PyCrypto.

like image 164
Gareth Latty Avatar answered Oct 05 '22 13:10

Gareth Latty


You could call random.SystemRandom instead. This will use CryptGenRandom on Windows and /dev/urandom on Linux.

Otherwise, there's always Cygwin's /dev/random?

like image 34
Soz Avatar answered Oct 05 '22 13:10

Soz


You could use random from Python's standard library.

like image 39
Steve Avatar answered Oct 05 '22 13:10

Steve