Algorithm for weighted ranges.

Get help using Construct 2

Post » Wed Apr 03, 2013 10:18 pm

I'm trying to come up with some pseudo code for spitting out numbers randomly, with weights.

So, I want to randomly spit out 1-10. But I want 1-6 to happen 75% of the time, 7-9 to happen 20% of the time and 10 to only happen 5%.

Basically I want there to be adjustable weights on the return. Any thoughts on this?
B
30
S
10
G
7
Posts: 416
Reputation: 7,239

Post » Wed Apr 03, 2013 10:27 pm

it's easy !

Compare 2 values ...

floor(random(1,100) <= 75
-- Set Variable to floor(random(1,6))

floor(random(1,100) => 75
floor(random(1,100) <= 95
-- Set Variable to floor(random(7,9))

floor(random(1,100) => 95
floor(random(1,100) <= 100
-- Set Variable to 10

Here we go ...
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Wed Apr 03, 2013 10:38 pm

*facepalm* That is perfect and I am dense.
B
30
S
10
G
7
Posts: 416
Reputation: 7,239


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, Artpunk, Magistross and 30 guests