Math Formula for "gradiated" randoms?

For questions about using Classic.

Post » 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
Follow me on Twitter @evgLabs
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

Post » 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.
Image Image
B
161
S
48
G
90
Posts: 7,350
Reputation: 66,755

Post » 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.
Follow me on Twitter @evgLabs
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

Post » 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]

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
B
51
S
10
G
7
Posts: 184
Reputation: 6,825

Post » 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
134
S
65
G
16
Posts: 1,766
Reputation: 19,190

Post » 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
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » 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
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » 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
134
S
65
G
16
Posts: 1,766
Reputation: 19,190

Post » 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.
Image Image
B
161
S
48
G
90
Posts: 7,350
Reputation: 66,755

Post » 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.

Link: [url:312t07ll]http://dl.dropbox.com/u/1010927/Forumpics/normalRandomTest.cap[/url:312t07ll]
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests