[ 
https://issues.apache.org/jira/browse/RNG-57?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16640891#comment-16640891
 ] 

Alex D Herbert commented on RNG-57:
-----------------------------------

Having though about this the simulation can be modelled as a Binomial 
distribution. 

Each Chi square test has a probability of failure of 0.01 (if the RNG is 
perfect).

Here's the CDF for a Binomial(n=500, p=0.01):
||Number of failures (k)||CDF(x <= k)||1 - CDF(x <= k)||
|0|0.0066|0.9934|
|1|0.0398|0.9602|
|2|0.1234|0.8766|
|3|0.2636|0.7364|
|4|0.4396|0.5604|
|5|0.6160|0.3840|
|6|0.7629|0.2371|
|7|0.8677|0.1323|
|8|0.9329|0.0671|
|9|0.9689|0.0311|
|10|0.9868|0.0132|
|11|0.9948|0.0052|
|12|0.9981|0.0019|
|13|0.9994|0.0006|
|14|0.9998|0.0002|
|15|0.9999|0.0001|
|16|1.0000|0.0000|

So the current limit of 10 will be exceeded at a rate of (1 - 0.9868) = 0.0132.

To make the test robust the p-value for failure can be set at p=0.001. Then the 
limit would have to be 13 failures.

If the RNG is not perfect then the Chi square test will fail more often than 1% 
of the time and this should easily be detected.

I'll collate the results from testing each provider with random seeds and see 
what the failure rate would be for each at different failure thresholds.

> CachedUniformRandomProvider for nextBoolean() and nextInt()
> -----------------------------------------------------------
>
>                 Key: RNG-57
>                 URL: https://issues.apache.org/jira/browse/RNG-57
>             Project: Commons RNG
>          Issue Type: Improvement
>          Components: sampling
>    Affects Versions: 1.2
>            Reporter: Alex D Herbert
>            Priority: Minor
>              Labels: performance
>
> Implement a wrapper around a {{UniformRandomProvider}} that can cache the 
> underlying source of random bytes for use in the methods {{nextBoolean()}} 
> and {{nextInt()}} (in the case of {{LongProvider}}). E.g.
> {code:java}
> LongProvider provider = RandomSource.create(RandomSource.SPLIT_MIX_64);
> CachedLongProvider rng = new CachedLongProvider(provider);
> // Uses cached nextLong() 64 times
> rng.nextBoolean();
> // Uses cached nextLong() twice
> rng.nextInt();
> IntProvider provider = RandomSource.create(RandomSource.KISS);
> CachedIntProvider rng2 = new CachedIntProvider(provider);
> // Uses cached nextInt() 32 times
> rng2.nextBoolean();
> // This could be wrapped by a factory method:
> UniformRandomProvider rng = CachedUniformRandomProviderFactory.wrap(
>         // Any supported source: IntProvider or LongProvider
>         RandomSource.create(RandomSource...));
> {code}
> The implementation should be speed tested to determine the benefit for 
> {{nextBoolean()}} and if {{nextInt()}} can be improved for {{LongProviders}}.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to