|
-
May 3rd, 2010, 06:58 AM
#16
Re: Random numbers
From Borland C++ 3.1 Help, article rand():
rand uses a multiplicative congruential random number generator with period
232 to return successive pseudo-random numbers in the range 0 to RAND_MAX.
It used to be so in some old C standard (C89 I guess), then it was fixed.
-
May 3rd, 2010, 07:02 AM
#17
Re: Random numbers
I think you're loosing some formatting there. I could believe a period of 2^32, not 232.....
-
May 3rd, 2010, 07:12 AM
#18
Re: Random numbers
This was copied exactly as it is in Borland C++ Help, I believe it was lost before:
Have a look:
(1) http://poli.cs.vsb.cz/c/help/stdlib0.htm#LBL66
(2) http://books.google.lv/books?id=_T-s...%20%22&f=false
-
May 3rd, 2010, 07:14 AM
#19
Re: Random numbers
Well, it's wrong. The period is 2^32 according to several other sources, and frankly that makes much more sense.
-
May 3rd, 2010, 07:23 AM
#20
Re: Random numbers
Just tested it on original Borland C++ 3.1. You're right, the period is longer than 232.
I'm surprised, this typo could survive through years and some printed books.
-
May 3rd, 2010, 08:27 AM
#21
Re: Random numbers
 Originally Posted by andrey_zh
Just tested it on original Borland C++ 3.1. You're right, the period is longer than 232.
I'm surprised, this typo could survive through years and some printed books.
It was probably 2³², but the formatting got lost and got transformed into 232.
As far as I know though, from a standards point of view, rand is entirely implementation dependent.
The only requirements are a seed, and for the output to be a linear distribution between 0 and RAND_MAX, RAND_MAX being implementation defined. Anything else is just speculation on the implementation. For all you know, RAND_MAX could be 32, and the implemention could be Mersenne, with a 2^19937 period.
...
On a side note, I wanted to add that in a PRNG using LCG the values in a "cycle" are completely independent of the seed. The seed only defines the starting point in the cycle.
Last edited by monarch_dodra; May 3rd, 2010 at 08:30 AM.
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
-
May 3rd, 2010, 04:15 PM
#22
Re: Random numbers
Hi again and sorry for being so insistent, but i am very interested in solving this task :
I know that the 1000 numbers have been generated using a function like the rand() of Visual C:
Xn+1=(a*Xn+c) mod 2^32
And after doing this, the numbers that we have access to are formed by extracting the bits 30-16 (length:15 bits- numbers range from 0 to 32767).
There has to be a way to calculate the 'a' and 'c' variables having the first 1000 numbers. I insist: i think that the paper "Inferring sequences produced by a linear congruential generator missing low-order bits" contains the algorithm to do that, but i don't have access to it. So, please, i need urgent help.
Thanks a lot!
-
May 3rd, 2010, 04:36 PM
#23
Re: Random numbers
Go ask on a math forum. They're more likely to be able to help, since you're looking for an equation to solve before you can even think about writing code.
Or just buy the paper.
Last edited by Lindley; May 3rd, 2010 at 04:39 PM.
-
May 3rd, 2010, 04:48 PM
#24
Re: Random numbers
 Originally Posted by mary_201091
Hi again and sorry for being so insistent, but i am very interested in solving this task :
I know that the 1000 numbers have been generated using a function like the rand() of Visual C:
Xn+1=(a*Xn+c) mod 2^32
And after doing this, the numbers that we have access to are formed by extracting the bits 30-16 (length:15 bits- numbers range from 0 to 32767).
There has to be a way to calculate the 'a' and 'c' variables having the first 1000 numbers. I insist: i think that the paper "Inferring sequences produced by a linear congruential generator missing low-order bits" contains the algorithm to do that, but i don't have access to it. So, please, i need urgent help.
Thanks a lot!
Seriously, just because the people here code, doesn't mean they hold advanced degrees in mathematics. You're asking your questions in the wrong place. Your problem may be related to programming, but your actual questions are purely mathematical.
-
May 3rd, 2010, 06:21 PM
#25
Re: Random numbers
 Originally Posted by Chris_F
Seriously, just because the people here code, doesn't mean they hold advanced degrees in mathematics. You're asking your questions in the wrong place. Your problem may be related to programming, but your actual questions are purely mathematical.
And just because you code doesn't mean you're mathematically challenged. To be a good programmer you should know some concrete math and this is well within the city limits.
Last edited by nuzzle; May 3rd, 2010 at 07:31 PM.
-
May 3rd, 2010, 06:27 PM
#26
Re: Random numbers
Understanding how to look up the relevant paper and implement it is a reasonable expectation. Even understanding the problem statement in mathematical terms.
Actually working out the solution, however, moves into the realm of research; and thus while many of us no doubt could do it given time, that isn't something we're likely to be spending large amounts of time on for someone else's benefit.
-
May 3rd, 2010, 06:42 PM
#27
Re: Random numbers
 Originally Posted by nuzzle
And just because you code doesn't mean you're mathematically challenged. To be a good programmer you should now some concrete math and this is well within the city limits.
Or so you say, but I have yet to see your proof.
Last edited by Chris_F; May 3rd, 2010 at 06:44 PM.
-
May 3rd, 2010, 07:40 PM
#28
Re: Random numbers
 Originally Posted by Chris_F
Or so you say, but I have yet to see your proof. 
Proof of what?
After the last post of the OP I think I know how to solve this problem but that's not important.
What's important is the discussion itself and who are you trying to curb it?
-
May 3rd, 2010, 08:05 PM
#29
Re: Random numbers
...... you use the LLL algorithm
Get Microsoft Visual C++ Express here or CodeBlocks here.
Get STLFilt here to radically improve error messages when using the STL.
Get these two can't live without C++ libraries, BOOST here and Loki here.
Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
Always use [code] code tags [/code] to make code legible and preserve indentation.
Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.
-
May 3rd, 2010, 08:30 PM
#30
Re: Random numbers
 Originally Posted by nuzzle
Proof of what?
I meant proof as in mathematical proof.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|