How to Generate Random Numbers: Poisson Distribution
Jump to navigation
Jump to search
Pages with syntax highlighting errors
Q Technical Reference
Q Technical Reference
Q Technical Reference > Setting Up Data > Creating New Variables
Q Technical Reference > Troubleshooting
Q Technical Reference > Updating and Automation > JavaScript
User Interface > JavaScript Variables > JavaScript Variables Examples Library
Create a new JavaScript Variable with the following Expression, where you replace 5 with your desired mean:
var mean = 5;
var L = Math.exp(-mean);
var p = 1.0;
var k = 0;
do {
k++;
p *= Math.random();
} while (p > L);
k - 1;
This example is based upon the first answer on stackoverflow.
See Also
- JavaScript Variables for detail on how to create new variables in the Variables and Questions tab using JavaScript.
- JavaScript for information about the JavaScript programming language.
- How to Generate Random Numbers: Uniform Distribution from 0 to 1.
Pages with syntax highlighting errors
Q Technical Reference
Q Technical Reference
Q Technical Reference > Setting Up Data > Creating New Variables
Q Technical Reference > Troubleshooting
Q Technical Reference > Updating and Automation > JavaScript
User Interface > JavaScript Variables > JavaScript Variables Examples Library