Code: Select all
Random,, % A_Now ^ A_TickCount ; as good as any seed
Blue = 36
green = 2
red = 13
yellow = 49
VarsListItDo =
( ltrim
Blue
Green
Red
Yellow
)
F5::MsgBox % WeightedRandomVarName(VarsListItDo)
WeightedRandomVarName( list )
{
Local R := 0 ; Global everything else
Loop, Parse, list, `n, `r %A_Tab%
R += Abs(%A_LoopField%) ; Abs() was required here... I don't know why
Random, R, 0, % R
Loop, Parse, list, `n, `r %A_Tab%
If ( 0 >= R -= %A_LoopField% )
Return A_LoopField
}
Code: Select all
Choices := ["glow stick", "needle", "stop sign", "blouse", "hanger", "rubber duck", "shovel", "bookmark", "model car", "tampon", "rubber band", "tire swing", "sharpie", "picture frame", "photo album", "nail filer", "tooth paste", "bath fizzers", "tissue box", "deodorant ", "cookie jar", "rusty nail", "drill press", "chalk", "word search", "thermometer ", "face wash", "paint brush", "candy wrapper", "shoe lace", "leg warmers", "wireless control", "boom box", "quilt", "stockings", "card", "tooth pick", "shawl", "speakers ", "key chain", "cork", "helmet", "mouse pad", "zipper", "glasses", "lamp shade", "sketch pad", "gage", "plastic fork", "flag", "clay pot", "check book", "CD"]
Loop,% Choices.MaxIndex()
MsgBox % Unique_RChoice(Choices)
Unique_RChoice(Array){
If (Array.MaxIndex() = 0 || Array.MaxIndex() = "")
return, "ERROR"
else {
Random,Rand,1,% Array.MaxIndex()
Ret := Array[Rand]
Array.Remove(Rand)
return, Ret
}
}