473,804 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mersenne Twister -- A Revised C++ Implementation

I've posted my revised C++ implementation of the Mersenne Twister at:

http://www.coyotegulch.com/libcoyote...istedRoad.html

This is "free-as-in-liberty" and "free-as-in-beer" code.

The Mersenne Twister is a "random number" generator invented by Makoto
Matsumoto and Takuji Nishimura; their website includes numerous
implementations of the algorithm.

Essentially, the Mersenne Twister is a very large linear-feedback shift
register. The algorithm operates on a 19,937 bit seed, stored in an
624-element array of 32-bit unsigned integers. The value 2^19937-1 is a
Mersenne prime; the technique for manipulating the seed is based on an
older "twisting" algorithm -- hence the name "Mersenne Twister".

An appealing aspect of the Mersenne Twister is its use of binary
operations -- as opposed to time-consuming multiplication -- for
generating numbers. The algorithm also has a very long period, and good
granularity. It is both fast and effective for non-cryptographic
applications.

--
Scott Robert Ladd
Coyote Gulch Productions (http://www.coyotegulch.com)
Software Invention for High-Performance Computing
Jul 22 '05
31 4447

"Carsten Hansen" <ha******@world net.att.net> wrote in message
news:_1******** ***********@bgt nsc05-news.ops.worldn et.att.net...

"kevin collins" <ke********@hot mail.com> wrote in message
news:pXTKb.7668 83$Tr4.2203330@ attbi_s03...
Carsten Hansen writes:
Generating random numbers with a given distribution has a well-established meaning.
Using that well-established meaning and given that a Normal
distribution
has
an infinite range, it does not make sense to talk about generating random numbers with a Normal distribution between 0 and 1.
You can calculate other things. But if you use a well-established phrase, you better qualify it.


I read Ladd's whole post as "good enough for government work". If I had
seen a similar thing in some high-falutin' mathematics journal, I would

have
applied different standards. After all, the computers I have seen have
been unable to express infinity in a reasonable fashion, anyway, one of

the
popular OSes limits RAM to only 2^29 bytes. Computers of the kind being
discussed here (that is, a machine, not a human) deal with

approximations for the real numbers encountered in the field of mathematics. C++, as

used
here, does not deal with symbolic mathematics.

I saw, and see, no reason for further qualification as to the use of the phrase, considering the context in which it was provided.

It is pretty clear that you are the kind of person that has to have the

last
word. So post it, I don't expect to express any answer.


This has nothing to do with how big a number you can represent on a
computer. When you have an infinite range and you claim it falls between 0
and 1 you are talking nonsense.


Okay if you want to stick to knit-picking then so be it. Stephen never
claimed that the infinite range falls between 0 and 1. He was only talking
about a normal distribution with mean 0.5 between the limits of 0 and 1. It
is of course correct that the Stiltjes-integral applied in mathematical
statistics is defined from -\inf to \inf. However, if you want to calculate
anything reasonable you will have to specify limits as infinity is a
mathematical construct that doesn´t play very well with practical
applications (to see this we only have to resort to Quantum Mechanics, which
is OT here and I don´t wanna get into that now). Specifying limits does
bring us back to numerical accuracy which depends on your machine and
therefore any applied limit is valid (see my previous post about the
Wiener-Levy process).

Regards
Chris

Jul 22 '05 #31

"Chris Theis" <Ch************ *@nospam.cern.c h> wrote in message
news:%k******** *********@news. chello.at...

"Carsten Hansen" <ha******@world net.att.net> wrote in message
news:_1******** ***********@bgt nsc05-news.ops.worldn et.att.net...

"kevin collins" <ke********@hot mail.com> wrote in message
news:pXTKb.7668 83$Tr4.2203330@ attbi_s03...
Carsten Hansen writes:

> Generating random numbers with a given distribution has a well-established
> meaning.
> Using that well-established meaning and given that a Normal distribution has
> an infinite range, it does not make sense to talk about generating

random
> numbers with a Normal distribution between 0 and 1.
> You can calculate other things. But if you use a well-established

phrase,
> you better qualify it.

I read Ladd's whole post as "good enough for government work". If I had seen a similar thing in some high-falutin' mathematics journal, I would
have
applied different standards. After all, the computers I have seen
have been unable to express infinity in a reasonable fashion, anyway, one of
the
popular OSes limits RAM to only 2^29 bytes. Computers of the kind
being discussed here (that is, a machine, not a human) deal with

approximations for the real numbers encountered in the field of mathematics. C++, as

used
here, does not deal with symbolic mathematics.

I saw, and see, no reason for further qualification as to the use of the phrase, considering the context in which it was provided.

It is pretty clear that you are the kind of person that has to have

the last
word. So post it, I don't expect to express any answer.


This has nothing to do with how big a number you can represent on a
computer. When you have an infinite range and you claim it falls between 0 and 1 you are talking nonsense.


Okay if you want to stick to knit-picking then so be it. Stephen never
claimed that the infinite range falls between 0 and 1. He was only talking
about a normal distribution with mean 0.5 between the limits of 0 and 1.

It is of course correct that the Stiltjes-integral applied in mathematical
statistics is defined from -\inf to \inf. However, if you want to calculate anything reasonable you will have to specify limits as infinity is a
mathematical construct that doesn´t play very well with practical
applications (to see this we only have to resort to Quantum Mechanics, which is OT here and I don´t wanna get into that now). Specifying limits does
bring us back to numerical accuracy which depends on your machine and
therefore any applied limit is valid (see my previous post about the
Wiener-Levy process).

Regards
Chris


You can have a truncated normal distribution. If you do, you specify the
mean, the standard deviation and the limits for the truncation.
That is fine. But that is not what Stephen wrote. He is calculating
something else (a cumulative probability).
Using the same name, generating random numbers with a Normal distribution,
for two different things is confusing and misleading.
There are no numerical accuracy issues here.

Carsten Hansen

Jul 22 '05 #32

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

Similar topics

31
3005
by: Raymond Hettinger | last post by:
Based on your extensive feedback, PEP 322 has been completely revised. The response was strongly positive, but almost everyone preferred having a function instead of multiple object methods. The updated proposal is at: www.python.org/peps/pep-0322.html In a nutshell, it proposes a builtin function that greatly simplifies reverse iteration. The core concept is that clarity comes from specifying a sequence in a forward direction and...
4
6177
by: Shufen | last post by:
Hi, I'm a newbie that just started to learn python, html and etc. I have some questions to ask and hope that someone can help me on. I'm trying to code a python script (with HTML) to get values from a html form that consists of about 10 checkbox and a textbox where user have to key in a value to perform a search. From python tutors, I learned that I have to use the following method:
7
2043
by: Jan Roland Eriksson | last post by:
I'm posting a revised version of the meta FAQ for this NG. Beware that there are a few links in there that does not have a resource available for them yet but, over and all, this following document should be usable as presented. Rip it apart at your own discretion... ===== Archive-name: www/stylesheets/newsgroup-faq
2
3304
by: Martin Ho | last post by:
Hi Everyone, I have this code of Mersenne twister, which produces the random numbers, one of the fastest codes as far as I know to produce random numbers. Anyways, it's writen in c# and I need to translate it to vb.net. I tried some translators and I can't get it to work. Could someone help me? This is the code:
26
2182
by: CBFalconer | last post by:
I have modified my ggets utility, to simplify the code and reduce the requirements on the standard library. The external action is totally unchanged, so there is no real need for anyone to upgrade. Available at: <http://cbfalconer.home.att.net/download/> -- Chuck F (cbfalconer@yahoo.com) (cbfalconer@maineline.net) Available for consulting/temporary embedded and systems.
0
1687
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 420 open ( +4) / 3410 closed ( +2) / 3830 total ( +6) Bugs : 915 open (+17) / 6186 closed ( +6) / 7101 total (+23) RFE : 235 open ( +1) / 238 closed ( +0) / 473 total ( +1) New / Reopened Patches ______________________
11
2726
by: Simon | last post by:
I have a quick question on the Mersenne Twister (hereinafter MT) I'm using the standard C code downloaded from the MT website (http://tinyurl.com/6d8t3). It's being used for a game to generate random levels, monsters, items and so on, and I want the game to be different each time I play it. The standard MT code gives me the same string of random numbers each time I run it. This is not surprising - computers are deterministic and it...
0
1131
by: bearophileHUGS | last post by:
This may be interesting for Python developers of the random module, "SIMD-oriented Fast Mersenne Twister (SFMT): twice faster than Mersenne Twister": http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/ One function may be useful to generate integers (randint, randrange, choice, shuffle, etc), the other for floating point values (random) faster than the current Mersenne Twister used in the random module.
1
2492
by: mjm2114 | last post by:
Hi there, I have a question on a naive implementation of a parallel MT that I've done using the fortran version of MT19937ar.f posted in Prof. Matsumoto's website. (http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/ MT2002/emt19937ar.html) First, I setup a KISS RNG (Marsaglia, 1999) in the master node and seed it. I then use the first 4 outputs from the master node to
0
9711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10595
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7633
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.