473,657 Members | 2,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

random number generator of Math.random() ?

Simple question: does the Java standard specify what random
number generator algorithm should be used for Math.random() ? If
'no', then can anybody tell me what PRNG is behind Sun's version
of Math.random()?

Thanks,
Bart

--
"Share what you know. Learn what you don't."
May 30 '06 #1
3 17701

"Bart Vandewoestyne" <My************ ********@telene t.be> wrote in message
news:11******** *******@seven.k ulnet.kuleuven. ac.be...
Simple question: does the Java standard specify what random
number generator algorithm should be used for Math.random() ?
Yes it does.
If
'no', then can anybody tell me what PRNG is behind Sun's version
of Math.random()?


See http://java.sun.com/j2se/1.5.0/docs/...il/Random.html

- Oliver

May 30 '06 #2
On 2006-05-30, Oliver Wong <ow***@castorte ch.com> wrote:
'no', then can anybody tell me what PRNG is behind Sun's version
of Math.random()?


See http://java.sun.com/j2se/1.5.0/docs/...il/Random.html


Hmm... so if I understand things correctly, the pseudo-random
numbers produced by Random.nextDoub le() are the same as the ones
produced by Math.random() and the underlying algorithm is the one
as specified in

http://java.sun.com/j2se/1.5.0/docs/...ml#nextDouble()

namely

public double nextDouble() {
return (((long)next(26 ) << 27) + next(27))
/ (double)(1L << 53);
}

Looking at Random.next() then tells me that the PRNG used here is a linear
congruential pseudorandom number generator, as defined by D. H. Lehmer and
described by Donald E. Knuth in The Art of Computer Programming, Volume 2:
Seminumerical Algorithms, section 3.2.1

So am I correct if I say that the Java standard specifies the above PRNG as the PRNG to use when implementing Math.random() ?

Bart

--
"Share what you know. Learn what you don't."
May 30 '06 #3

"Bart Vandewoestyne" <My************ ********@telene t.be> wrote in message
news:11******** *******@seven.k ulnet.kuleuven. ac.be...
[...]
public double nextDouble() {
return (((long)next(26 ) << 27) + next(27))
/ (double)(1L << 53);
}
[...] So am I correct if I say that the Java standard specifies the above PRNG
as the PRNG to use when implementing Math.random() ?


Yes, I think so, or at least one which returns the exact same set of
numbers given the same initial seed.

- Oliver

May 30 '06 #4

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

Similar topics

10
11946
by: Nicholas Geraldi | last post by:
Im looking for a decent random number generator. Im looking to make a large number of random numbers (100 or so, if not more) in a short period of time (as fast as possible). the function i was using to get random numbers was Random rn = new Random(System.currentTimeMillis()); but it seems that the system doesn't update the milliseconds often enough to cause a true randomaziation (i ran just the System.currentTimeMillis() in a
10
2494
by: Virus | last post by:
Ok well what I am trying to do is have 1.) the background color to change randomly with 5 different colors.(change on page load) 2,) 10 different quotes randomly fadeing in and out in random spots on the webpage. with a delay timer on them, so they keep changing as the page is open. Not random each time the page is loaded. If anyone can help it would be greatly appreaciated, I have tried many of
4
2490
by: lharby | last post by:
I'm hoping this is very simple. I am currently using a random quote generator on our intranet. I have 17 quotes, when I add in an 18th and change the makeArray number the code seems not to work. This works: <script LANGUAGE="JavaScript"> function makeArray(len) {
70
6233
by: Ben Pfaff | last post by:
One issue that comes up fairly often around here is the poor quality of the pseudo-random number generators supplied with many C implementations. As a result, we have to recommend things like using the high-order bits returned by rand() instead of the low-order bits, avoiding using rand() for anything that wants decently random numbers, not using rand() if you want more than approx. UINT_MAX total different sequences, and so on. So I...
13
3608
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 distribution random number generator and then using the function in another part of my program in order to use the value. This function is called for many iterations. The problem is, through each run I am getting the exact same number generated...
40
2800
by: RadiationX | last post by:
I have a problem that I really don't understand at all. In my previous post I could get started on my projects I just had a few problems with syntax errors. This problem is something that I don't conceptually understand very well. Here it is: Π – the ratio of the circumference of a circle to its diameter – is one of the most common and important constants in mathematics. It is an irrational number (a real number that cannot be...
14
4740
by: avanti | last post by:
Hi, I need to generate random alphanumeric password strings for the users in my application using Javascript. Are there any links that will have pointers on the same? Thanks, Avanti
13
2801
by: Peter Oliphant | last post by:
I would like to be able to create a random number generator that produces evenly distributed random numbers up to given number. For example, I would like to pick a random number less than 100000, or between 0 and 99999 (inclusive). Further, the I want the range to be a variable. Concretely, I would like to create the following method: unsigned long Random( unsigned long num )
11
3017
TTCEric
by: TTCEric | last post by:
This will be original. I promise. I cannot get the random number generator to work. I tried seeding with Date.Now.Milliseconds, it still results in the same values. What I have are arrays of values. I get a random index value for each array so I can pull the data from them.
0
8427
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
8850
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...
0
8746
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8626
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...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6178
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
5649
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();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.