On Wed, 10 Nov 2004 21:34:10 -0700, Steve Johnson <[EMAIL PROTECTED]> wrote:
> The following code produces about a half-million random 32-bit
> integers/sec. on my Pentium M 1.7Ghz based Latitude D800:
>
> byte[] buf = new byte[4];
>
> RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
>


Forgot to mention that the following line is what you would do in a
loop.  The buffer is allocated only once and the RNG is created only
once.

> int val = Rand(buf, rng);



>
> ...
>
> int Rand(byte[] buffer, RNGCryptoServiceProvider rng)
> {
>         rng.GetBytes(buffer);
>         return BitConverter.ToInt32(buffer, 0);
> }


--
Steve Johnson

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com
Some .NET courses you may be interested in:

Essential .NET: building applications and components with C#
November 29 - December 3, in Los Angeles
http://www.develop.com/courses/edotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to