• ### Announcements

• #### Submit Your Images for Pic of the Day04/04/2017

You can submit your image for Pic of the Day consideration on our Official Second Life Flickr page

# twoDx : normal - skew - uniform distributions

## Recommended Posts

across the street I came across a discussion about skew, normal and uniform distributions for use  in LSL game code

as this is a new forum interface and as I have started over again recently then for my first post under my new tag I will repost on here what I posted over there

+

a 2-die multi-face method that skews from a normal distribution at one end to a uniform distribution at the other end

```integer twoDx(integer a, integer b, integer m)
{
integer n = ((integer)llFrand(a) + (integer)llFrand(b)) % m;
if (a > b) // skew low
return m - 1 - n;
return n;
}

default
{
state_entry()
{
list counts;
integer i;

integer rounds = 500;

integer die1 = 5;
integer die2 = 6;
integer magnitude = 10;

for (i = 0; i < magnitude; i++)
counts += [0];
for (i = 0; i < rounds; i++)
{
integer value = twoDx(die1, die2, magnitude);
counts = llListReplaceList(counts,[llList2Integer(counts, value) + 1], value, value);
}
for (i = 0; i < magnitude; i++)
llSay(0, (string)i + ": " + llList2String(counts, i));
}
}```

distributions for magnitude = 10 and one die having 5 faces

```twoDx(5,6,10) :: normal
values: 0 1 2 3 4 5 6 7 8 9
counts: 1 2 3 4 5 5 4 3 2 1

twoDx(5,7,10) :: skew hi
values: 0 1 2 3 4 5 6 7 8 9
counts: 2 2 3 4 5 5 5 4 3 2

twoDx(8,5,10) :: skew lo
values: 0 1 2 3 4 5 6 7 8 9
counts: 3 4 5 5 5 5 4 3 3 3

twoDx(5,9,10) :: skew hi
values: 0 1 2 3 4 5 6 7 8 9
counts: 4 4 4 4 5 5 5 5 5 4

twoDx(5,10,10) :: uniform
values: 0 1 2 3 4 5 6 7 8 9
counts: 5 5 5 5 5 5 5 5 5 5```