LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


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

Rep: Reputation: Disabled
Super period


http://en.wikipedia.org/wiki/Linear_..._in_common_use

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 07:53 AM.
 
Old 03-03-2014, 08:38 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,738

Rep: Reputation: 955Reputation: 955Reputation: 955Reputation: 955Reputation: 955Reputation: 955Reputation: 955Reputation: 955
You have your bit counts a bit mixed up.
Code:
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, 12:47 AM   #3
l0p3n
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 12:57 AM.
 
  


Reply


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 06:24 PM
a good random number generator in C++ asmahan Linux - Software 2 08-24-2009 01:40 PM
I need a random number generator newbiesforever Linux - Software 5 05-22-2009 02:04 PM
random number generator vkmgeek Programming 3 09-02-2008 09:41 AM
Random number generator for linux Steve_Taylor Programming 12 09-30-2001 04:21 PM


All times are GMT -5. The time now is 10:27 PM.

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