If you don't like using black-box R functions, or you don't have access to these functions, here are simple options to simulate deviates from various distributions. They can even be implemented in Excel! You first need to simulate uniform deviates on [0, 1]. If you don't trust the function available in your programming language, here is a good alternative:
rnd = 1000
for (n=0; n<20000; n++) {
rnd=(10232193 * rnd + 3701101) % 54198451371
Rand= rnd / 54198451371
}
This code produces 20,000 deviates of a uniform distribution on [0, 1]. The deviates are stored in the variable named Rand. The symbol % stands for the modulo operator.
Now, assuming Rand, Rand1 and Rand2 are uniform deviates on [0, 1], here is how to sample deviates from various other distributions:
Normal(0, 1) and log-normal deviates:
Exponential deviates of parameter Lambda:
Geometric deviates of parameter P:
Power law deviates with exponent B, on [0, A]:
Do you know any simple formula to generate other types of deviates?
Tags:
Can you recommend any references you can recommend that list parameters for Linear Congruent Generators and document their statistical performance? Most sources (like Wikipedia) list parameters with little discussion of statistical properties.
Hi Dennis, the choice of the parameters in my linear congruent generator is a little arbitrary. I played with various values until I found ones that give a long enough period. So my solution is not spectacular by any means, especially since I was just trying to get a far better generator than the one available in the Perl programming language (that one can only produce 32,767 different values.)
I'm researching the topic for a project, and will be happy to share my notes.
Basically, I need enough documentation to satisfy clients (including convincing them that we don't need a cryptographic grade random number generator).
I thought this was a good paper and references some pretty robust methods.
https://link.springer.com/content/pdf/10.1007%2Fs12095-017-0225-x.pdf
Thanks Dennis, and if you find a better one than mine, please share. Should be easy. Likewise, I don't need weapon-grade cryptography.
© 2020 Data Science Central ® Powered by
Badges | Report an Issue | Privacy Policy | Terms of Service
Most Popular Content on DSC
To not miss this type of content in the future, subscribe to our newsletter.
Other popular resources
Archives: 2008-2014 | 2015-2016 | 2017-2019 | Book 1 | Book 2 | More
Most popular articles