OiMunk Posted November 28, 2008 Share Posted November 28, 2008 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.. thanks, Func getInterval() $2=_GUICtrlSlider_GetPos($slider2) $3=_GUICtrlSlider_GetPos($slider3)+$2 $4=_GUICtrlSlider_GetPos($slider4)+$3 $5=_GUICtrlSlider_GetPos($slider5)+$4 $6=_GUICtrlSlider_GetPos($slider6)+$5 $7=_GUICtrlSlider_GetPos($slider7)+$6 $8=_GUICtrlSlider_GetPos($slider8)+$7 $9=_GUICtrlSlider_GetPos($slider9)+$8 $10=_GUICtrlSlider_GetPos($slider10)+$9 $11=_GUICtrlSlider_GetPos($slider11)+$10 $12=_GUICtrlSlider_GetPos($slider12)+$11 $13=_GUICtrlSlider_GetPos($slider13)+$12 ;total of all the weighted variables $Int=random(1,$13,1) Select 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 EndSelect EndFunc Link to comment Share on other sites More sharing options...
cageman Posted November 28, 2008 Share Posted November 28, 2008 (edited) 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 $numberarray[$i]=_GUICtrlSlider_GetPos($slider[$i])+$numberarray[$i-1] Else $numberarray[$i]=_GUICtrlSlider_GetPos($slider[$i]) Endif Next $Int=random(1,$numberarray[13],1) for $j=3 to 13 step 1 if $Int<$numberarray[$i] Then return $j-1 Endif Next if $int>$numberarray[12] Then return 13 Endif Endfunc Edited November 28, 2008 by cageman Link to comment Share on other sites More sharing options...
OiMunk Posted November 30, 2008 Author Share Posted November 30, 2008 Thanks, that's quite useful, cheers Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now