Math Formula for "gradiated" randoms?

This forum is currently in read-only mode.
From the Asset Store
Aliens are invading our planet! Solve the math question, and attack the alien with your laser. Covers addition, subtract
  • Hi, I'm not sure if I made up a new word. But here's what I'm after:

    I want to generate a random value for a bunch of sprite's (0-100) which is easy, but the thing that has stumped me is, I want to make the high value more rare. So you could easily find sprites with random of 0-10 but would have to search a long time for 90-100.

    I know I could event out every factor of 10 or some thing like that, but does anyone know if there's an easy way to do this?

    Thanks

  • Well the hard part would probably be the picking, but I would think:

    for each?

    sprite set value"variable" to random(global value"ran")

    global add 1 to value "ran"

    Would be pretty close.

  • I don't think that'd work.

    As an example generate a random value:

    0-30 -- 50% of the time

    31-60 -- 35% of the time

    61-100 -- 15% of the time

    not necessarily that but something similar.

  • I don't think that'd work.

    As an example generate a random value:

    0-30 -- 50% of the time

    31-60 -- 35% of the time

    61-100 -- 15% of the time

    not necessarily that but something similar.

    What about something like this.

    Generate a random number between 0-190

    Send to a private variable

    If Equal to or less than 90-Divide by 3 and round

    If between 91-150- Subtract 60 then Divide by two then round

    If Greater than 150- Subtract 90 then round

    I believe that should give you

    0-30 -- 9/19 of the time

    31-60 -- 6/19 of the time

    61-100 -- 4/19 of the time

  • You could take the sqaure root of random number then round it, this will make lower numbers rarer, but you could minus that value from 100 so that higher values are rarer.

    100 - (round(random(10000)^0.5))

    or you could make it even harder to get 100

    100 - (round(random(1000000)^0.33))

    That works for me, don't know if thats the best way to do it though.

    Here's a cap showing the numbers.

  • sin(random(91))*100

    values near 100 should be less rare than those near 0

    if you want it the other way around

    100-sin(random(91))*100

    That'll make 100 rare and 0 common.

    if i have them (rarity curb) mixed up sorry, but these formulas should work to give you "gradiations".

  • NormalRandom(mean, sigma)

    Generates a random number according to a normal distribution.

    <img src="http://3.bp.blogspot.com/_BoiGN8E7WGw/TLdmU21-oVI/AAAAAAAAAFk/ac1TVK0RdQM/s400/Normal_distribution_and_scales.gif">

    Mean is the number, sigma is the width of the curve/standard deviation.

  • Nice davio, I'm not as good at math can you show how to use the NormalRandom() thing for this 1-100 thing?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well mean means average, so your curve will be any number in range of the mean up or down.

    So say your mean is 10, and the sigma is 10 you will get any random number between 10-10, and 10+10....

    At least that's my understanding, not getting those results however.....

    Oh, and you'll probably need an int() in there, for matching.

  • So say your mean is 10, and the sigma is 10 you will get any random number between 10-10, and 10+10....

    Kind of, but sigma is just the width of the bell curve. Specifying 10 doesn't actually mean it will give you a number that's either ten greater or ten less. Here, I made this .cap. A sigma of 4 gives you around about a 32 number deviation from the mean with normally distributed probabilities. Any number is actually possible, but the chance is really small. You should clamp the value if you want it to stay within a certain range.

    Link: http://dl.dropbox.com/u/1010927/Forumpics/normalRandomTest.cap

  • The math geek in me forced me to register just to answer this question.

    There's a really simple way to get almost exactly what you're after: For every random value you need, generate two random values and pick the lowest. For values of 1-100, that should give you:

    1-30: 51% of the time

    31-60: 33% of the time

    61-100: 16% of the time

    1-10: 19% of the time

    91-100: 1% of the time

    Should be about the same for 0-100.

  • ^

    Just tested this out and it works pretty good, with the exception that the number 100 will never be returned because your always choosing the lower value.

  • but what if they're both 100?

  • Well the formula I used was:

    set pv1 to ran(100)+1, set pv2 to ran(100)+1

    if pv1 is less than pv2 set pv3 to pv1

    if pv2 is less than pv1 set pv3 to pv2

    So basically duplicates are bypassed.

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