Welcome Guest
You last visited December 14, 2017, 11:43 am
All times shown are
Eastern Time (GMT-5:00)

# Random Number Transforms - Normal Distribution

Topic closed. 2 replies. Last post 11 years ago by JADELottery.

 Page 1 of 1
- Eagle Sun - Quantum Master
West Concord, MN
United States
Member #21
December 7, 2001
4025 Posts
Online
 Posted: November 24, 2006, 3:15 pm - IP Logged

Random Number Transforms - Normal Distribution

Analog -      x = ±Ö-2s² ln(1 - y)

Decimal -    x = ±(Ö-2s² ln(1 - y) - (s / 2))

Digital -      x = ±(Ö-n ln(1 - y) - ((1 / 2) * Ön / 2))

y - random number, 0 £ y < 1
s - standard deviation
n - digital deviation, | x | £ n
x - transformed random number
± - values of x randomly alternate

Analog values are not rounded to any fixed decimal or integer.

Decimal values of x are rounded to nearest fixed decimal place or integer.
Example: 2.591230102345664 is rounded to 2.59.

Digital values of x are rounded to the nearest integer.
Example: 2.591230102345664 is rounded to 3.
Digital limits are valid y samples are when | x | £ n.
If | x | > n, then resample y.

Relationship of n and s  -      n = 2 s²  and    s = Ön / 2

I'll follow up later with some explanations and examples.

Presented 'AS IS' and for Entertainment Purposes Only.
Any gain or loss is your responsibility.

Order is a Subset of Chaos
Knowledge is Beyond Belief
Wisdom is Not Censored
Douglas Paul Smallish
Jehocifer

- Eagle Sun - Quantum Master
West Concord, MN
United States
Member #21
December 7, 2001
4025 Posts
Online
 Posted: November 25, 2006, 5:13 am - IP Logged

I don't use the analog transform by itself too much; I mostly use the decimal and digital. The decimal is used when a known value of s is available. The digital is used to achieve an integer distribution in the range of -n to n values. There are two parts of the equation that need to be randomized, the y value and the sign (±) value. Below are the functions I use in Visual Basic to generate the decimal and digital transforms.

Decimal function VB code

Function Rand_SD(s As Double) As Double 'Random Normal Distribution - Standard Deviation s

If Rnd < 0.5 Then 'Randomize sign value
sx = -1 '- when random number less than 0.5
Else
sx = 1 '+ when random number greater than or equal to 0.5
End If

Rand_SD = sx * (Sqr(-2 * s * s * Log(1 - Rnd)) - (s / 2))

End Function

Digital function VB code

Function Rand_ID(n As Long) As Long 'Random Normal Distribution - Integer Deviation n

If n >= 1 Then 'check to see if n is greater than or equal to 1
'if 0 or less, set Rand_ID to 0
Do 'setup sample loop

x = Round(Rand_SD(Sqr(n / 2))) 'get random x value
'based on standard deviation of s = sqr(n / 2)
Loop Until Abs(x) <= n 'resample if absolute value of x is greater than n

Rand_ID = x

Else

Rand_ID = 0

End If

End Function

Presented 'AS IS' and for Entertainment Purposes Only.
Any gain or loss is your responsibility.

Order is a Subset of Chaos
Knowledge is Beyond Belief
Wisdom is Not Censored
Douglas Paul Smallish
Jehocifer

- Eagle Sun - Quantum Master
West Concord, MN
United States
Member #21
December 7, 2001
4025 Posts
Online
 Posted: November 25, 2006, 5:04 pm - IP Logged

Here's an example of the digital transform for 1,500 random samples when n = 10:

1,500 Random Digital Samples, n = 10

-3, -2, -1, 0, 3, 1, 0, -1, 1, 2, 2, -1, 1, -1, 1, 4, -1, -1, 2, 3, -1, -2, 0, 0, -3, 3, 1, 3, -1, 0, -2, 0, 3, -4, -2, 0, 3, -3, -2, -1, 0, 3, 0, -1, 1, -1, 3, 2, -6, 4, -1, 2, -2, 3, -1, 2, -3, 0, 0, 1, 3, -2, 5, -2, 1, 0, -1, 0, 1, 0, -3, 4, 1, 1, 0, 4, -1, -2, 0, 1, 0, 0, 3, -1, 1, -3, 2, -2, 0, 1, 0, -5, 2, 1, 0, 3, 0, -4, 1, -2, 0, 1, 3, 2, 3, -4, -1, -3, 5, 0, -4, -2, -2, -5, 2, -4, 0, 2, -1, 2, 3, -2, -1, 2, -2, 0, 2, 3, 1, 0, 0, 1, -4, 0, 1, -2, -1, 1, -1, 1, 1, -3, 0, 1, 4, 4, 1, 1, -4, 3, -1, -2, 0, -2, 0, 2, 2, -3, -1, -1, 3, -1, 2, 0, -2, -1, -3, 0, 2, 0, -4, -2, -2, 0, 1, -2, 4, -3, 2, 0, 1, 1, -1, 1, 0, -4, -1, 1, 6, 0, 0, 1, 1, -1, 1, -3, 3, -1, -1, 1, 1, -1, -3, -5, -1, 3, -2, -2, 1, -2, 0, 3, 0, -2, 0, -1, 2, 1, 1, 4, 3, -3, -2, -2, 2, 1, 2, 0, 0, -1, -1, -2, -1, 2, 4, -1, 0, -4, 1, 1, 0, 2, 2, -1, 1, -2, -2, -2, 0, 3, 2, 2, -2, 2, 2, -1, -1, -1, 2, 2, 2, -4, -3, 0, 1, -2, -4, 2, 4, 5, 1, -2, 2, -4, 0, -1, 0, -1, 0, 3, -2, 3, 3, 3, 1, 1, 2, 2, 3, 0, 0, 1, 1, -2, -1, -2, 0, 0, -1, -1, 2, -3, 1, 0, 5, 1, -6, 3, -3, 2, -2, 2, -2, 0, 2, -1, 3, 3, -2, 3, -3, 0, -1, 3, -3, 2, -4, 1, 1, 4, 1, 0, -2, 0, -1, -2, 2, -1, 0, 3, -3, 0, 0, 3, 0, -3, 2, 0, 1, 1, 1, 6, 0, -2, 2, -4, -4, 1, 0, 1, 5, 2, 1, 0, -3, -2, -4, -4, 2, 2, -2, -1, -4, 1, -5, -1, -2, -1, 2, 3, 0, -1, 2, -3, -2, -1, 3, -1, 0, 2, -2, -2, 2, -1, 1, -4, 0, 0, 3, -2, 2, 1, 2, 1, 5, 0, 0, 2, 0, -1, 1, 1, 3, 4, 0, 3, -3, 1, -2, -3, 1, 0, 1, 2, -3, 1, -3, 0, 1, -1, 3, 2, 0, 0, 0, -2, 2, -1, -1, -2, 0, 1, -2, 2, 0, 1, 2, 0, -2, 0, 1, 1, -1, 2, 5, 0, 2, -3, 2, 2, 1, 0, 2, -1, 0, 1, 0, 1, 3, 3, 1, 0, -2, -2, 0, -1, 2, 4, 2, 0, 3, 2, -2, 3, 0, 0, 0, 4, -2, -1, -2, 0, 0, -1, -4, 0, -1, -1, 0, -3, 0, -1, 3, -2, 0, 1, 2, 0, -1, -3, 0, -3, 1, -1, 4, 0, -1, 0, 3, 3, 2, 1, 2, 2, -3, 1, 2, -1, -1, -1, 4, 3, -1, -1, -2, 1, -2, 2, 3, 1, -3, -1, 6, -3, 0, 0, 0, -1, 2, -1, -2, 1, -2, -1, 0, -1, 0, 1, -1, -2, -1, 1, -1, -3, 0, 1, 1, -1, 3, 0, -1, 0, -5, -3, 2, -4, 2, -3, -2, -1, 2, -3, -1, 2, 3, 1, -4, 1, 4, 1, -6, -5, 2, 0, 4, 1, -2, -1, 3, 0, -1, -1, -1, 0, -1, -1, 0, 4, -2, -1, -1, 0, 0, 4, -2, 0, 1, -1, -3, 1, 6, -3, 0, 0, 0, -1, 2, -2, 4, 0, 3, 3, 3, 3, 1, -3, -1, 0, 0, 2, -2, 2, -4, 0, 2, -2, -1, 2, 6, 0, 2, -1, -1, -1, 3, -2, -1, -2, 0, 3, 1, 1, 0, 2, 1, 0, -4, 0, 1, 4, 0, 1, 1, 1, 0, 0, 3, -2, 1, -4, 1, 1, 0, -2, -3, 2, -1, 1, -2, 0, 0, 0, -1, 2, -2, -4, 1, 4, 0, 4, 1, 0, 1, -2, 2, 3, -4, 5, 2, -3, -1, -3, 0, 0, -4, -1, 8, -1, 3, 0, 0, 0, -1, -1, -3, -4, -2, 2, -4, -3, -1, -3, 3, -3, 1, -1, 1, 4, 3, -1, -2, 2, 1, -4, -1, 3, -3, 4, 1, 1, 3, 2, -3, 3, -4, 1, -1, 4, -1, 2, -2, -2, 3, -2, -1, 2, -1, -6, 0, 1, -2, 0, 2, 0, 1, 0, 1, 0, -2, -1, -3, 1, 0, -2, 2, -2, 0, -1, -3, 1, 0, 2, 0, 0, 5, 0, -2, 1, 2, 3, -2, -4, 0, 0, 1, -4, 0, 0, 0, 0, 5, 0, -1, 0, 2, 3, 4, 1, 3, -2, 1, 3, 0, 0, 0, -1, -2, -3, -2, 2, 0, -3, 3, -1, 0, -3, -4, -3, 0, 2, 2, -1, -2, 1, -2, 1, 4, 0, -2, 3, -4, 3, 2, 1, 3, 1, 2, 0, 1, 3, -3, 0, 0, 2, 0, 1, 0, -1, 2, -1, -2, -1, 0, 2, 2, -2, -1, 3, 3, -6, 3, 2, -1, 2, 1, -2, 0, 0, -1, -1, 1, -2, 0, -5, 3, 0, 3, 2, -1, -2, -1, 2, 1, 1, 3, 3, -1, 1, -1, -1, -6, 1, -2, -3, -4, 1, -5, 1, -2, 0, 4, 2, -3, 0, 1, -2, -2, -4, 0, 1, -5, -1, 3, 0, -1, 1, 0, 1, 2, -4, 3, 2, -1, 0, 1, -4, -1, -1, 1, 0, 0, 4, 0, 2, -3, 7, 0, -4, -1, 3, 5, 1, 0, 3, -3, 2, -1, 0, -1, 0, 1, 2, -3, -1, -1, 2, 1, -3, 0, -3, -6, -3, 1, 0, 2, 3, 0, 9, -1, -2, 2, -2, 0, 0, -1, -3, 0, 0, -5, 2, 0, 0, 0, -1, 0, 1, 0, -1, 2, 0, -5, 3, -3, 1, 0, 1, -1, -3, 1, -4, 2, 1, -2, 1, 1, 1, -2, 0, 2, 1, -4, -1, 1, -3, 4, -3, -1, 1, 0, -3, -4, 2, 2, 0, -2, 0, -1, 2, -3, 2, 1, 1, 2, 4, -2, -3, 2, 2, 2, -2, -2, -1, 0, -2, 0, -4, 0, -3, -1, -1, 0, -4, 3, 0, 3, 0, 0, 0, 1, -2, -4, 2, 8, 1, 1, 0, 3, -2, 0, -2, 4, 4, -1, 2, 0, -2, -2, 1, 3, 0, -2, 0, 0, 5, 0, 1, 0, 0, 5, 0, 0, -3, 2, -4, -3, -1, 1, 3, -2, -1, 0, 1, 1, -3, -1, -2, -2, -2, 0, -4, -2, -1, -1, 2, 2, 3, 3, -4, -3, 1, 1, -3, -2, -1, 0, 0, 2, -1, 2, -2, -2, -2, 1, -1, -4, 1, -1, 1, -3, 4, 3, 0, -1, -1, -4, 0, 2, 6, 0, 3, 0, -4, 4, -5, 1, -2, -3, 4, 5, -4, 2, 0, 0, 0, 0, 2, 0, -1, 0, -1, 5, 4, -1, 5, 2, -5, 0, 1, 2, 1, -1, -2, 4, -1, -2, -1, 4, -3, 4, 0, -5, -3, 0, -1, 2, -6, 2, 2, 2, -1, 2, 1, 0, -2, 0, 0, 0, 3, 1, 0, -1, -5, 0, 0, 0, 2, -2, 2, -1, -1, -2, -2, 0, 5, 0, 0, 2, 2, -1, 0, 1, -1, 0, 1, -3, -1, -1, 0, 4, -2, 0, 0, -2, 0, 3, 0, -1, 0, -2, 1, -1, -4, 0, -3, -1, 5, 0, -3, 0, 3, 0, 1, -1, 1, -3, 2, -4, 1, -2, 0, -2, 0, 0, -1, -1, 3, -2, -1, -1, -4, 3, -3, -2, -2, -3, -3, -1, 2, 0, -1, -5, 1, 3, 1, -1, 0, 0, 1, 0, -4, 1, 2, -3, -1, 3, 2, 0, 3, 0, 2, -4, -2, 2, -1, 3, -3, 1, 0, 3, 2, -2, -2, -2, 0, 5, 3, 0, 4, 0, 0, -1, 0, 4, 0, -1, -2, 5, 4, -2, 2, -5, -2, -3, 0, -2, -3, 3, -1, -2, 2, 1, -3, -1, -1, 0, 2, -2, 1, 0, -1, -1, 3, 0, 2, -2, 4, 1, 0, 1, -1, 4, 1, 0, 4, -3, -1, 1, 5, -1, 1, -1, 5, 0, 3, 1, 5, -1, 3, 0, 0, 4, 0, -3, -5, 1, 1, -1, -1, 2, 0, 3, -3, -1, -1, 0, -2, -2, 0, 0, -2, 0, -1, -4, -1, 1, -2, 0, 2, 0, 1, -2, -4, 1, 0, 3, 1, -3, 2, -3, 1, 3, -3, 4, -6, 0, 3, 3, 0, -3, 0, 0, -1, 0, 1, 0, 1, -1, -2, -2, 3, 0, 4, 1, -2, 1, -3, 1, -5, 1, -2, -2, -3, -1, -3, 2, -2, 1, 0, 5, -1, -1, -4, -1, 0, -2, 1, 3, 0, -1, -3

Random Digital Frequency Table, n = 10

 Random Normal x Actual Calculated -10 0 0.01 -9 0 0.08 -8 2 0.44 -7 0 1.99 -6 6 7.31 -5 26 21.97 -4 57 54.03 -3 118 108.81 -2 165 179.39 -1 247 242.15 0 282 267.62 1 226 242.15 2 170 179.39 3 112 108.81 4 57 54.03 5 28 21.97 6 3 7.31 7 0 1.99 8 1 0.44 9 0 0.08 10 0 0.01

Graph of Random Digital Frequency Table

Presented 'AS IS' and for Entertainment Purposes Only.
Any gain or loss is your responsibility.