Any way to do normal distributed random number generator?

Discussion and feedback on Construct 2

Post » Wed Jul 16, 2014 10:25 pm

As per topic,
I am currently trying to figure out how to create a normal distributed random number generator using the existing C2 expression, random().
I am trying to make sense of the calculation involved in it but my math isn't that good.
Anyone ever do this before?
Help would be highly appreciated
B
36
S
18
G
11
Posts: 248
Reputation: 8,694

Post » Wed Jul 16, 2014 10:39 pm

"random()" will produce a floating point (decimal) number between 0 and 1 Ex. 0.24523 at which point you can round or perform some math to clean up the number as desired.

To choose from a list of possible values you can do "choose(1,2,3)" which will randomly select either 1,2,3 as per the example. Is that what you mean by distributed?
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Wed Jul 16, 2014 11:00 pm

troublesum wrote:"random()" will produce a floating point (decimal) number between 0 and 1 Ex. 0.24523 at which point you can round or perform some math to clean up the number as desired.

To choose from a list of possible values you can do "choose(1,2,3)" which will randomly select either 1,2,3 as per the example. Is that what you mean by distributed?


No.
I am refering to instead of making the probability of each number within a range have an equal chance of getting picked which is what C2 random() do, I want to make an RNG where the central numbers in the range have vastly higher chance to be randomly selected than the lowest and highest numbers.
To picture it
Image

This is the website with codes I think is viable to do what I aimed for, yet I am still unsure on how to do it in C2.
http://rosettacode.org/wiki/Statistics/ ... stribution
B
36
S
18
G
11
Posts: 248
Reputation: 8,694

Post » Wed Jul 16, 2014 11:08 pm

Ahh.. out of my league... good luck :)
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Thu Jul 24, 2014 11:42 am

Use two (or more) randomly generated numbers for the distributed value.
example:
random (1,6) + random (1,6) will generate a result from 2 to 12 with 7 being the normal value.
B
4
Posts: 1
Reputation: 200

Post » Thu Jul 24, 2014 12:56 pm

If Apshai is correct in his formula, use int(random(1,7)) + int(random(1,7)) to indeed generate a result for 2 to 12 only made of integers.
The int() allows to make sure only integers are returned and the max range value in the random() function is never reached, so if you want a result at some point to actually be 6, go for a max range of 7.

I think I remember a long time ago the very same subject being discussed in the forums already (like back in 2012/2011).
I can't remember exactly the formula given in the end, and I don't remember if there wasn't a recommendation to actually use round(), ceil() or int().

I can't seem to find back the discussion though, I hope this helps you nonetheless.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
296
S
119
G
96
Posts: 7,332
Reputation: 71,306

Post » Thu Jul 24, 2014 3:50 pm

oooh. classic bell curve with dice. If you ever want to to work with this style of random number formula distribution. RPG.net developer corner is far better place. Probablility theory is big in that area.

though you can also check out

Very common to use very robust.
http://anydice.com/

harder to use, but can produce formula that anydice can't... though anydice can do a lot.
http://topps.diku.dk/torbenm/troll.msp
B
92
S
18
G
9
Posts: 2,455
Reputation: 15,113

Post » Thu Jul 24, 2014 4:55 pm

I found a formula for it called the Box-Muller transform, and it looks like this:
NormalRandom = mean + sqrt(std_deviation * -2 * ln(1 - random(1))) * cos(360 * (1-random(1)))

Works pretty good in tests:
https://dl.dropboxusercontent.com/u/542 ... andom.capx

Edit:
didn't look at your link till now.
B
94
S
33
G
118
Posts: 5,396
Reputation: 75,853

Post » Sat Jul 26, 2014 5:48 am

R0J0hound wrote:I found a formula for it called the Box-Muller transform, and it looks like this:
NormalRandom = mean + sqrt(std_deviation * -2 * ln(1 - random(1))) * cos(360 * (1-random(1)))

Works pretty good in tests:
https://dl.dropboxusercontent.com/u/542 ... andom.capx

Edit:
didn't look at your link till now.


Thanks, that's what I am looking for :D .
B
36
S
18
G
11
Posts: 248
Reputation: 8,694


Return to Construct 2 General

Who is online

Users browsing this forum: Peticha and 11 guests