473,386 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Internal details of System.Random

I am looking for a source for the internal details of the
System.Random pseudo random number generator. Something reasonably
technical please, not how to use it (which I know) but more how does
it work under the hood.

Failing that I have three specific questions:

1 Is the core PRNG using integer arithmetic or floating point
arithmetic? The presence of Sample() makes me suspect that it is
floating point.

2 Is the protected method Sample() faster, slower or about the same as
the public method NextDouble()?

3 Is there anything special about Sample() compared to the way
NextDouble() operates?

For amusement I am building a PRNG class derived from System.Random so
it is useful to know a bit of detail about the internals of the base
class so I can make the best use of it.

Thanks in advance,

rossum

--

The ultimate truth is that there is no ultimate truth
Jan 12 '06 #1
4 1624
If you want to achive just better performance use this one:
http://www.codeproject.com/csharp/FastRandom.asp

--
Milosz Skalecki
MCP, MCAD
"rossum" wrote:
I am looking for a source for the internal details of the
System.Random pseudo random number generator. Something reasonably
technical please, not how to use it (which I know) but more how does
it work under the hood.

Failing that I have three specific questions:

1 Is the core PRNG using integer arithmetic or floating point
arithmetic? The presence of Sample() makes me suspect that it is
floating point.

2 Is the protected method Sample() faster, slower or about the same as
the public method NextDouble()?

3 Is there anything special about Sample() compared to the way
NextDouble() operates?

For amusement I am building a PRNG class derived from System.Random so
it is useful to know a bit of detail about the internals of the base
class so I can make the best use of it.

Thanks in advance,

rossum

--

The ultimate truth is that there is no ultimate truth

Jan 12 '06 #2
On Thu, 12 Jan 2006 08:10:04 -0800, Milosz Skalecki
<mi*****@REMOVEITwp.pl> wrote:
If you want to achive just better performance use this one:
http://www.codeproject.com/csharp/FastRandom.asp


Thanks for the link Milosz. Although I probably won't use the
FastRandom generator, the performance table and some of the text on
that page was very helpful. The link says:

"System.Random is actually very fast and achieves its speed mostly by
only using simple and fast arithmetic operations such as shift and
add. However, the whole class is based around a central Sample()
method that returns a double between 0.0 and 1.0, and thus there is
some unnecessary floating point arithmetic used to generate integer
values."

The timing for NextDouble() shows it is about twice as fast as
NextInt(). This probably measn that as I suspected, System.Random is
based on a floating point PRNG with Sample() as the basic generator.

rossum

--

The ultimate truth is that there is no ultimate truth
Jan 12 '06 #3
Hi again,

You aked about implementation details of the System.Random class. I'm not
sure about .NET 1.0/1.1 but .NET 2.0 uses implementation of the Random class
based on Donald E. Knuth's subtractive random number generator algorithm.
(see D. E. Knuth. "The Art of Computer Programming, volume 2: Seminumerical
Algorithms". Addision-Wesley, Reading, MA, second edition, 1981.). I suspect
previous version of .NET uses this implementation as well.

Hope this helps
--
Milosz Skalecki
MCP, MCAD
"rossum" wrote:
On Thu, 12 Jan 2006 08:10:04 -0800, Milosz Skalecki
<mi*****@REMOVEITwp.pl> wrote:
If you want to achive just better performance use this one:
http://www.codeproject.com/csharp/FastRandom.asp


Thanks for the link Milosz. Although I probably won't use the
FastRandom generator, the performance table and some of the text on
that page was very helpful. The link says:

"System.Random is actually very fast and achieves its speed mostly by
only using simple and fast arithmetic operations such as shift and
add. However, the whole class is based around a central Sample()
method that returns a double between 0.0 and 1.0, and thus there is
some unnecessary floating point arithmetic used to generate integer
values."

The timing for NextDouble() shows it is about twice as fast as
NextInt(). This probably measn that as I suspected, System.Random is
based on a floating point PRNG with Sample() as the basic generator.

rossum

--

The ultimate truth is that there is no ultimate truth

Jan 13 '06 #4
On Fri, 13 Jan 2006 03:17:01 -0800, Milosz Skalecki
<mi*****@REMOVEITwp.pl> wrote:
Hi again,

You aked about implementation details of the System.Random class. I'm not
sure about .NET 1.0/1.1 but .NET 2.0 uses implementation of the Random class
based on Donald E. Knuth's subtractive random number generator algorithm.
(see D. E. Knuth. "The Art of Computer Programming, volume 2: Seminumerical
Algorithms". Addision-Wesley, Reading, MA, second edition, 1981.). I suspect
previous version of .NET uses this implementation as well.

Hope this helps

Thanks again, that is useful. I have a copy of Knuth so I shall look
it up.

rossum
--

The ultimate truth is that there is no ultimate truth
Jan 13 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bp | last post by:
I'm writing a simple HTTPRequest that retrieves the content of a web page. Dim httpReq As System.Net.HttpWebRequest Dim httpResp As System.Net.HttpWebResponse httpReq =...
5
by: NG | last post by:
Hi, We are having DB2-V7.2 DB on AIX 5.2 machine. Recently we upgraded our system to fixpack 13 and activated activate AIX asynchronous IO function. Our DB is going to crash recovery with...
13
by: Jon Agiato | last post by:
Hello, I am sure this problem is easy to spot but I have been at this project all day and the frustration has finally overcome me. I am using this function in order to produce a standard normal...
6
by: David Lack | last post by:
Hi, I recently installed a 60-day trial of .NET 2003 on my development system. I made tests with previous personal projects (which compiled ok with VC6) and some open source files, and keep...
1
by: D A H | last post by:
I have gotten the same exception in multiple projects. I have solved the underlying problem. My question is if anyone knew of a setting that would cause this exception to be thrown. A...
9
by: JT | last post by:
Here is the overall structure I will be referring to: End-program ProvideWorkFlow.dll Forms and methods that properly manipulate calls to methods in AccessUtils AccessUtils (a web service)...
6
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I am thinking about doing this since I got several cases that some of our internal users open more than one browser at the same time from our server. When one of the transactions was not...
0
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi guys! My newly built website has just recently went online, but sometimes I face errors (randomly) like these: System.IndexOutOfRangeException: There is no row at position 0....
2
by: Spam Catcher | last post by:
Hi all, I have a webservice which is throwing a 500 Internal Server Error. It seems to be related to the signature of function (or one of the properties within the function). The web service...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.