[SciPy-dev] Re: [Numpy-discussion] Release of scipy corebetawillhappen next week.

Robert Kern rkern at ucsd.edu
Tue Sep 27 21:42:32 CDT 2005


Charles Harris wrote:
> Robert Kern wrote:
> 
>>times as you like with different states (another benefit of the
>>/dev/urandom seeding over seeding with the time; there's no real chance
> 
> I like /dev/urandom, but is it portable?

Lots of UNIX-like systems have it now. I don't think any OS has a
/dev/urandom that *isn't* an uninterruptable stream of random bits.

> What is the windows equivalent?

Here's the snippet from RandomKit:

/* Windows crypto */
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif
#include <windows.h>
#include <wincrypt.h>
#endif

...

	HCRYPTPROV hCryptProv;
	BOOL done;

	if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL,
		CRYPT_VERIFYCONTEXT) || !hCryptProv)
		return RK_ENODEV;
	done = CryptGenRandom(hCryptProv, size, (unsigned char *)buffer);
	CryptReleaseContext(hCryptProv, 0);
	if (done)
		return RK_NOERR;

> I've been wondering, as I run linux and /dev/urandom is always handy.
> 
> I also think some provision for setting a simple seed, perhaps just a long,
> is useful for testing when it is nice to have a repeatable sequences.

Way ahead of you.  :-)

    def seed(self, seed=None):
        """Seed the generator.

        seed(seed=None)

        seed can be an integer, an array (or other sequence) of integers
of any
        length, or None. If seed is None, then RandomState will try to
read data
        from /dev/urandom (or the Windows analogue) if available or seed
from
        the clock otherwise.
        """

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter




More information about the Scipy-dev mailing list