An example of an algorithm for generating a random value in a data set with a normal distribution?

I am trying to create some random numbers with a simple uneven probability in order to simulate realistic data for testing purposes. I am looking for a function that takes mu and sigma as parameters and returns x, where probably x is in certain ranges, follows a standard call curve or so. It does not have to be super accurate or even effective. The resulting dataset does not have to match the exact mu and sigma that I set. I'm just looking for a relatively simple uneven random number generator. Limiting the set of possible return values ​​for int would be nice. I have seen many suggestions there, but no one seems to be suitable for this simple case.

+3
source share
2 answers

Convert Box-Muller in a nutshell:

First we get two independent uniform random numbers from the interval (0, 1], call them U and V.

Then you can get two independent distributed random numbers with unit normals from the formulas

X = sqrt(-2 * log(U)) * cos(2 * pi * V);
Y = sqrt(-2 * log(U)) * sin(2 * pi * V);

This gives you random numbers for mu = 0, sigma = 1; set sigma = s, multiply your random numbers by s; to set mu = m, add m to your random numbers.

+3
source

My first thought is why can't you use the existing library? I'm sure most languages ​​already have a library for creating regular random numbers.

- , , @ellisbben, . () 12 :

X = -6 ## We set X to be -mean value of 12 uniforms
for i in 1 to 12:
   X += U

X . 10 ^ 5 .

enter image description here

0

Source: https://habr.com/ru/post/1769261/


All Articles