# Math Formula for "gradiated" randoms?

### » Wed Dec 15, 2010 12:25 am

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
B
34
S
14
G
4
Posts: 251
Reputation: 4,074

### » Wed Dec 15, 2010 12:39 am

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.
B
179
S
50
G
208
Posts: 8,724
Reputation: 128,816

### » Wed Dec 15, 2010 1:02 am

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.
B
34
S
14
G
4
Posts: 251
Reputation: 4,074

### » Wed Dec 15, 2010 1:24 am

[quote="YetAnotherSuperhero":2upa8s0y]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.[/quote:2upa8s0y]

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
B
56
S
12
G
7
Posts: 184
Reputation: 7,150

### » Wed Dec 15, 2010 1:45 am

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.
B
168
S
81
G
22
Posts: 1,815
Reputation: 24,863

### » Wed Dec 15, 2010 1:51 am

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".
B
79
S
13
G
8
Posts: 1,977
Reputation: 9,947

### » Wed Dec 15, 2010 2:02 am

NormalRandom(mean, sigma)
Generates a random number according to a normal distribution.

Mean is the number, sigma is the width of the curve/standard deviation.
B
49
S
10
G
9
Posts: 1,224
Reputation: 8,480

### » Wed Dec 15, 2010 2:09 am

Nice davio, I'm not as good at math can you show how to use the NormalRandom() thing for this 1-100 thing?
B
168
S
81
G
22
Posts: 1,815
Reputation: 24,863

### » Wed Dec 15, 2010 5:17 am

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.
B
179
S
50
G
208
Posts: 8,724
Reputation: 128,816

### » Wed Dec 15, 2010 5:56 am

[quote="newt":312t07ll]So say your mean is 10, and the sigma is 10 you will get any random number between 10-10, and 10+10....[/quote:312t07ll]
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.

B
49
S
10
G
9
Posts: 1,224
Reputation: 8,480

Next