Jump to content
Sign in to follow this  

selecting random weighted variables

Recommended Posts


My script needs to pick a random number between 2 and 13, but the chance of each number coming up needs to be altered according to user choices (GUI).

There must be a better way to do this with arrays or something..


Func getInterval()












$13=_GUICtrlSlider_GetPos($slider13)+$12 ;total of all the weighted variables



case $Int<$3

return 2

case $Int<$4

return 3

case $Int<$5

return 4

case $Int<$6

return 5

case $Int<$7

return 6

case $Int<$8

return 7

case $Int<$9

return 8

case $Int<$10

return 9

case $Int<$11

return 10

case $Int<$12

return 11

case $Int<$13

return 12

case $Int>$12

return 13



Share this post

Link to post
Share on other sites

for the code below to work you need to put your sliders into an array + declare a array numberarray which holds all the values for $2,$3,$4 etc.

it might not work at once, but i hope this helps you in the right direction.

Func getInterval()

for $i=2 to 13 step 1
if $i>2 Then 


for $j=3 to 13 step 1
if $Int<$numberarray[$i] Then
return $j-1

if $int>$numberarray[12] Then
return 13

Edited by cageman

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.