Sign in to follow this  
Followers 0
primeval

Random of precents

4 posts in this topic

Help me to get compact and correct script.

Here what i got:

Dim $i[4]
$i[0] = 0
$i[1] = 16
$i[2] = 34
$i[3] = 50

$rnd = Radnom(1, 100, 1)
;i need to make choise based on $i precent from random number, how to? have no idea:(

Sorry for my english.

Share this post


Link to post
Share on other sites



Hi, Primeval and welcome to the Forums. Your code works, you've simply mispelled Random. The snippet below shows me the random number just fine.

Dim $i[4]
$i[0] = 0
$i[1] = 16
$i[2] = 34
$i[3] = 50

$rnd = Random(1, 100, 1)
MsgBox(0, "", $rnd)

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

this will only return items from your array.

Global $rnd

Dim $i[4]
$i[0] = 0
$i[1] = 16
$i[2] = 34
$i[3] = 50

_rando()

while 1
for $k = 0 to ubound($i) - 1
If $rnd = $i[$k] Then
    msgbox (0, '' , $i[$k])
    _rando ()
else
    _rando()
endif
Next
WEnd


func _rando ()
    $rnd = Random(0, 100, 1)
endfunc

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks for reply, but, i try to explain what i whant to do.

Dim $i[4], $choise

;random precents may be any
$i[0] = 16
$i[1] = 0
$i[2] = 34
$i[3] = 50

$rnd = Random(1, 100, 1)
;i need to make choise based on $i precent from random number, how to? have no idea:(
Select
Case $rnd <= $i[0]
    $choise = 0
Case $rnd <= $i[0] + $i[1]
    $choise = 1
Case $rnd <= $i[0] + $i[1] + $i[2]
    $choise = 2
Case $rnd <= $i[0] + $i[1] + $i[2] + $i[3]
    $choise = 3
EndSelect

MsgBox(0,0,"Random was:" & $rnd & "   Choise:" & $choise)

Here, but i gues there is a way to make it more compact or somesing? if yes will thanksfull for any way to do it:)

Thanks for replays anyway.

Edited by primeval

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  
Followers 0