Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-01-2014, 08:43 AM   #1
LQ Newbie
Registered: Jul 2013
Distribution: Ubuntu
Posts: 27

Rep: Reputation: Disabled
Super period

One of the random number generators in Java extract the higher-order bits of the random number in order to get a longer period.

I'm not sure if I understand how this is done. Suppose that the random number r = 0000 1100 1000 1101. If we extract the 16 most significant bits from r; is the new number r = 0000 1100 or r = 0000 1100 0000 0000?

Last edited by l0p3n; 03-01-2014 at 08:53 AM.
Old 03-03-2014, 09:38 PM   #2
Senior Member
Registered: Nov 2005
Distribution: Arch
Posts: 3,026

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
You have your bit counts a bit mixed up.
A 48 bit random number, the internal value Xn
0011 0111  0000 1010  0111 1101  1001 0000  0111 1101  1110 1011

32 high bits, what is returned from Math.random()
0011 0111  0000 1010  0111 1101  1001 0000
Note that the lower 16 bits are not thrown away, they just aren't given to the application (caller of random()).
Old 03-04-2014, 01:47 AM   #3
LQ Newbie
Registered: Jul 2013
Distribution: Ubuntu
Posts: 27

Original Poster
Rep: Reputation: Disabled
If I have understood this correctly the 48 bits will be saved and used when generating the next random number. But what is returned as the random number to the calling application are the 32 higher-order bits of the generated number?

Last edited by l0p3n; 03-04-2014 at 01:57 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pseudo Random Generator is not initialized from the (entropy pool) !!!!? LinuxInDepth Red Hat 1 04-29-2012 07:24 PM
a good random number generator in C++ asmahan Linux - Software 2 08-24-2009 02:40 PM
I need a random number generator newbiesforever Linux - Software 5 05-22-2009 03:04 PM
random number generator vkmgeek Programming 3 09-02-2008 10:41 AM
Random number generator for linux Steve_Taylor Programming 12 09-30-2001 05:21 PM

All times are GMT -5. The time now is 08:19 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration