Any way to do normal distributed random number generator?

0 favourites
  • 9 posts
From the Asset Store
High quality backgrounds for games and videos with over 1000 images!
  • 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

  • "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?

  • "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

    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

  • Ahh.. out of my league... good luck

  • 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.

  • 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.

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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 <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy"> .

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)