My experiments show that the random number generator
in Microsoft's VC++6 compiler is a statistical RNG with a
significance level 1.0%.
Statistical testing at SL >1.0% (for example 1.001%) passes the test,
but 1.0% does not pass...
Can anybody confirm this finding?
The RNG function of the various SW products can be
analyzed and classified better using its significance level
as shown above.
I think this IMO important finding deserves a deeper research... :-)
For the testing method see: http://en.wikipedia.org/wiki/Binomial_test http://en.wikipedia.org/wiki/Binomial_distribution
Jul 11 '08
26 1543
"Jerry Coffin" <jc*****@taeus. comwrote:
jo*@iamnotathom e.org.invalid says...
[ ... ]
The two loops I used are not that important.
I just simulate 30 days with each day 500 rand's (ie. spins, draws etc.).
At the beginning of each day the frequency stats are cleared.
Ie. the tests are done for intraday stats only.
I hope this makes it clear.
BTW, there is also a parallel discussion on this in sci.math
under the subject "Detecting biased random number generators".
Out of curiosity, what exact code are you using to get from the original
range of the generator to the 0-35 that you're using?
Jerry, it is 0 to 36.
As recommended in many books (for example Phillip Good
"Permutatio n, Parametric and Bootstrap Tests of Hypotheses")
I use the following:
int genrand(int lo, int hi)
{
int z = rand() % (hi - lo + 1) + lo;
return z;
}
....
int r = genrand(0, 36);
joe said:
<snip>
Pete, can you confirm that then the max possible value
one can get is RAND_MAX - 1, and not RAND_MAX ?
He can't, because it isn't so.
The Standard says that "RAND_MAX [...] expands to an integral constant
expression, the value of which is the maximum value returned by the rand
function".
<snip>
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
"Richard Heathfield" <rj*@see.sig.in validwrote:
>
The Standard says that "RAND_MAX [...] expands to an integral constant
expression, the value of which is the maximum value returned by the rand
function".
My final version:
int genrand(unsigne d range)
{ // generates random number between 0 and range-1
// range can be maximally RAND_MAX + 1
// THIS IS THE RECOMMENDED CORRECT METHOD
// (recommended by me and others :-)
if (range < 2)
return 0;
if (range (RAND_MAX + 1))
range = RAND_MAX + 1;
const unsigned maxr = RAND_MAX + 1 - ((RAND_MAX + 1) % range);
unsigned value = maxr;
while (value >= maxr)
value = rand();
return value % range;
}
In article <g5**********@a ioe.org>, jo*@iamnotathom e.org.invalid says...
[ ... ]
Jerry, it is 0 to 36.
Okay -- not that it makes any real difference in terms of the algorithm.
As recommended in many books (for example Phillip Good
"Permutatio n, Parametric and Bootstrap Tests of Hypotheses")
I use the following:
int genrand(int lo, int hi)
{
int z = rand() % (hi - lo + 1) + lo;
return z;
}
...
int r = genrand(0, 36);
I had a hunch you might be doing it in a manner that was biased, and I
was right. Here's how I do it:
#include <stdlib.h>
int rand_lim(int limit) {
/* return a random number between 0 and limit inclusive.
*/
int divisor = RAND_MAX/(limit+1);
int retval;
do {
retval = rand() / divisor;
} while (retval limit);
return retval;
}
--
Later,
Jerry.
The universe is a figment of its own imagination.
On 2008-07-12 22:59:09 -0400, "joe" <jo*@iamnotatho me.org.invalids aid:
"Richard Heathfield" <rj*@see.sig.in validwrote:
>> The Standard says that "RAND_MAX [...] expands to an integral constant expression, the value of which is the maximum value returned by the rand function".
My final version:
int genrand(unsigne d range)
{ // generates random number between 0 and range-1
// range can be maximally RAND_MAX + 1
// THIS IS THE RECOMMENDED CORRECT METHOD
// (recommended by me and others :-)
if (range < 2)
return 0;
if (range (RAND_MAX + 1))
range = RAND_MAX + 1;
This last step isn't right. If the caller asks for random numbers in a
particular range, either return random numbers in that range or report
an error.
--
Pete
Roundhouse Consulting, Ltd. ( www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
( www.petebecker.com/tr1book)
On Jul 13, 2:35 pm, Pete Becker <p...@versatile coding.comwrote :
On 2008-07-12 22:59:09 -0400, "joe" <j...@iamnotath ome.org.invalid said:
"Richard Heathfield" <r...@see.sig.i nvalidwrote:
The Standard says that "RAND_MAX [...] expands to an integral constant
expression, the value of which is the maximum value returned by the rand
function".
My final version:
int genrand(unsigne d range)
{ // generates random number between 0 and range-1
// range can be maximally RAND_MAX + 1
// THIS IS THE RECOMMENDED CORRECT METHOD
// (recommended by me and others :-)
if (range < 2)
return 0;
if (range (RAND_MAX + 1))
range = RAND_MAX + 1;
This last step isn't right.
<snip>
It's redundant, but not wrong.
On 2008-07-13 09:17:51 -0400, vi******@gmail. com said:
On Jul 13, 2:35 pm, Pete Becker <p...@versatile coding.comwrote :
>On 2008-07-12 22:59:09 -0400, "joe" <j...@iamnotath ome.org.invalid said:
>>"Richard Heathfield" <r...@see.sig.i nvalidwrote:
>>>The Standard says that "RAND_MAX [...] expands to an integral constant expression , the value of which is the maximum value returned by the rand function".
>>My final version:
>>int genrand(unsigne d range) { // generates random number between 0 and range-1 // range can be maximally RAND_MAX + 1 // THIS IS THE RECOMMENDED CORRECT METHOD // (recommended by me and others :-)
>>if (range < 2) return 0; if (range (RAND_MAX + 1)) range = RAND_MAX + 1;
This last step isn't right.
<snip>
It's redundant, but not wrong.
How is it redundant? If the caller asks for a range that's larger than
this distribution can handle and this check isn't present, the
algorithm will not return values that cover the requested range.
--
Pete
Roundhouse Consulting, Ltd. ( www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
( www.petebecker.com/tr1book)
On Jul 13, 5:04 pm, Pete Becker <p...@versatile coding.comwrote :
On 2008-07-13 09:17:51 -0400, vipps...@gmail. com said:
On Jul 13, 2:35 pm, Pete Becker <p...@versatile coding.comwrote :
On 2008-07-12 22:59:09 -0400, "joe" <j...@iamnotath ome.org.invalid said:
>"Richard Heathfield" <r...@see.sig.i nvalidwrote:
>>The Standard says that "RAND_MAX [...] expands to an integral constant expression, the value of which is the maximum value returned by the rand function".
>My final version:
>int genrand(unsigne d range) { // generates random number between 0 and range-1 // range can be maximally RAND_MAX + 1 // THIS IS THE RECOMMENDED CORRECT METHOD // (recommended by me and others :-)
>if (range < 2) return 0; if (range (RAND_MAX + 1)) range = RAND_MAX + 1;
This last step isn't right.
<snip>
It's redundant, but not wrong.
How is it redundant? If the caller asks for a range that's larger than
this distribution can handle and this check isn't present, the
algorithm will not return values that cover the requested range.
Whether that second if is present or not, the behavior of the
algorithm is the same.
On 2008-07-13 10:11:09 -0400, vi******@gmail. com said:
On Jul 13, 5:04 pm, Pete Becker <p...@versatile coding.comwrote :
>On 2008-07-13 09:17:51 -0400, vipps...@gmail. com said:
>>On Jul 13, 2:35 pm, Pete Becker <p...@versatile coding.comwrote : On 2008-07-12 22:59:09 -0400, "joe" <j...@iamnotath ome.org.invalid said:
>>>>"Richard Heathfield" <r...@see.sig.i nvalidwrote:
>>>>>The Standard says that "RAND_MAX [...] expands to an integral constant >expression , the value of which is the maximum value returned by the rand >function ".
>>>>My final version:
>>>>int genrand(unsigne d range) { // generates random number between 0 and range-1 // range can be maximally RAND_MAX + 1 // THIS IS THE RECOMMENDED CORRECT METHOD // (recommended by me and others :-)
>>>>if (range < 2) return 0; if (range (RAND_MAX + 1)) range = RAND_MAX + 1;
>>>This last step isn't right. <snip> It's redundant, but not wrong.
How is it redundant? If the caller asks for a range that's larger than this distribution can handle and this check isn't present, the algorithm will not return values that cover the requested range.
Whether that second if is present or not, the behavior of the
algorithm is the same.
It should produce an error. The fact that it doesn't means it's wrong,
not that it's redundant.
--
Pete
Roundhouse Consulting, Ltd. ( www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
( www.petebecker.com/tr1book)
On Jul 13, 6:48 pm, Pete Becker <p...@versatile coding.comwrote :
On 2008-07-13 10:11:09 -0400, vipps...@gmail. com said:
On Jul 13, 5:04 pm, Pete Becker <p...@versatile coding.comwrote :
On 2008-07-13 09:17:51 -0400, vipps...@gmail. com said:
>On Jul 13, 2:35 pm, Pete Becker <p...@versatile coding.comwrote : On 2008-07-12 22:59:09 -0400, "joe" <j...@iamnotath ome.org.invalid said:
>>>"Richard Heathfield" <r...@see.sig.i nvalidwrote:
>>>>The Standard says that "RAND_MAX [...] expands to an integral constant expressio n, the value of which is the maximum value returned by the rand function" .
>>>My final version:
>>>int genrand(unsigne d range) { // generates random number between 0 and range-1 // range can be maximally RAND_MAX + 1 // THIS IS THE RECOMMENDED CORRECT METHOD // (recommended by me and others :-)
>>>if (range < 2) return 0; if (range (RAND_MAX + 1)) range = RAND_MAX + 1;
>>This last step isn't right. <snip> It's redundant, but not wrong.
How is it redundant? If the caller asks for a range that's larger than
this distribution can handle and this check isn't present, the
algorithm will not return values that cover the requested range.
Whether that second if is present or not, the behavior of the
algorithm is the same.
It should produce an error. The fact that it doesn't means it's wrong,
not that it's redundant.
You're wrong. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Grant Robertson |
last post by:
I am interested in including classification info in metadata. I am aware
of the Dublin Core and XMP. However, neither of these appear to specify
exactly how the classification data should be formatted within the
element.
I am interested in any standardized formats for expressing Dewey Decimal
System - DDS, Library of Congress Classification - LCC, Cutter Expansive
Classification, Universal Decimal Classification - UDC, Colon Notation...
|
by: joe |
last post by:
My experiments show that the random number generator
in Microsoft's VC++6 compiler is a statistical RNG with a
significance level 1.0%.
Statistical testing at SL >1.0% (for example 1.001%) passes the test,
but 1.0% does not pass...
Can anybody confirm this finding?
The RNG function of the various SW products can be
analyzed and classified better using its significance level
|
by: Rain |
last post by:
Hi,
I noticed the other day when I was trying to optimise the traffic on a
particular web page that it had significant viewstate even though I had
turned it off for most of the controls. So in a bold step I decided to
attempt to set viewstate on the form itself off which had a massive impact
on the viewstate like 80K to 15k.
So my question is what is the significance of turning off the viewstate for
the form and what information...
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |