Math Formula for "gradiated" randoms?

For questions about using Classic.

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

Post » Fri Dec 17, 2010 10:25 am

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

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.
B
1
G
2
Posts: 2
Reputation: 629

Post » Fri May 20, 2011 2:05 pm

^
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.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Fri May 20, 2011 2:27 pm

but what if they're both 100?
B
134
S
65
G
16
Posts: 1,765
Reputation: 19,188

Post » Fri May 20, 2011 2:46 pm

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.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Previous

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 9 guests