Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

C++11 random addon

License

NotificationsYou must be signed in to change notification settings

stdfin/random

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A collection of C++11 compatible random engines and distributions.

Random engines

ItemDescription
ThreefryA fast, high quality random number generator used or large scale parallel processing.
VandercorputA simplest one dimensional low-discrepancy sequence.

Random distributions

ItemDescription
Non-central Chi SquaredThe distribution of the sum of squares ofk Normal distributed variates each with variance one andlambda the sum of squares of the normal means.

Threefry engine

The Threefry random number engine is a fast and high quality random number generator used for large scale parallel processing.

The implementation is based on a paper byJohn Salmon and Mark Moraes and described in their paperParallel Random Numbers: As Easy as 1, 2, 3. (Proceedings of 2011 International Conference for High Performance Computing, Networking, Storage and Analysis). The algorithm is based on the Threefish cryptographic cipher.

  • Fast. Faster than the C++ Mersenne Twister.
  • High quality. Passes ALL the BigCrush test in the TestU01 framework.
  • Cyle length 2^258

Usable for large scale parallel processing:

  • O(1) discard() / jump-ahead makes is very easy to give each thread its own subsequence.
  • 32 bit seed offers 2^32 parallel random streams of length 2^258.
  • Streams are guaranteed to be non-overlapping,

example:

#include<iostream>#include"stdfin/random/threefry.hpp"intmain(){    stdfin::threefry_engine eng1, eng2;     eng1.seed(0);// reset the first engine (not really necessary)    eng2.seed(1);// 2nd engine gets a different seed     std::cout <<"\nTwo independent streams.\n";for (int i=0; i<4; ++i)        std::cout <<eng1() <<"" <<eng2() <<"\n"; }

gives

Two independent streams.3871888695 1931275270153194173 1458582871725456645 36042768681435770706 3225543903

Vandercorput engine

A van der Corput sequence is the simplest one dimensional low-discrepancy sequence over the unit interval first published in 1935 by the Dutch mathematician J. G. van der Corput. It is constructed by reversing the base n representation of the sequence of natural numbers (1, 2, 3, …).

Low-discrepancy sequence have an advantage over pure random numbers in that they cover the domain of interest quickly and evenly. They have an advantage over grids in that those only give high accuracy when the number of datapoints is pre-set whereas in using low-discrepancy sequence the accuracy improves continually as more datapoints are added.

#include<iostream>#include"stdfin/random/vandercorput_engine.hpp"intmain(){     stdfin::vandercorput_engine eng;for (int i=0; i<10; ++i)        std::cout <<eng() <<"\n";        }

Non-central Chi Squared distribution

The noncentral chi-squared distribution is a real valued distribution with two parameter,k andlambda. The distribution produces values > 0.

This is the distribution of the sum of squares ofk Normal distributed variates each with variance one andlambda the sum of squares of the normal means.

The distribution function is$$\displaystyle P(x) = \frac{1}{2} e^{-(x+\lambda)/2} \left( \frac{x}{\lambda} \right)^{k/4-1/2} I_{k/2-1}( \sqrt{\lambda x} )$$

where

$$\displaystyle I_\nu(z)$$ is a modified Bessel function of the first kind.

About

C++11 random addon

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp