Toffen Posted August 13, 2008 Share Posted August 13, 2008 How can i prevent the same random number twice. Etc Random = (1,10,1) If the first random is 9 i dont want 9 to show up at the next random number Thanks Link to comment Share on other sites More sharing options...
CHronologist Posted August 13, 2008 Share Posted August 13, 2008 you could store the numbers in an array and if the number was found reroll Link to comment Share on other sites More sharing options...
Andreik Posted August 13, 2008 Share Posted August 13, 2008 How can i prevent the same random number twice. Etc Random = (1,10,1) If the first random is 9 i dont want 9 to show up at the next random number Thanks Try this: #include <Array.au3> Dim $randomArray[11] FillArrayRandom($randomArray, 1, 10, 1) _ArrayDisplay($randomArray) Func FillArrayRandom(ByRef $array, $min, $max, $maxOccurence, $round = 0, $maxTries = 10000) Local $i, $number For $i = 1 to UBound($array)-1 For $n = 0 to $maxTries $number = Round(Random($min, $max), $round) If $maxOccurence = 0 OR _KeyInArrayCount($array, $number) < $maxOccurence Then ExitLoop Next If _KeyInArrayCount($array, $number) >= $maxOccurence Then Return SetError(1) $array[$i] = $number Next EndFunc Func _KeyInArrayCount($array, $key) Local $i, $n = 0 For $i = 1 to UBound($array)-1 If $array[$i] = $key Then $n += 1 Next Return $n EndFunc When the words fail... music speaks. Link to comment Share on other sites More sharing options...
monoceres Posted August 13, 2008 Share Posted August 13, 2008 Sure, I remembered writing a function that generated an array with random numbers that didn't repeat themselves.It's posted in autoit wrappers #515701 Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Toffen Posted August 13, 2008 Author Share Posted August 13, 2008 Thanks for help Link to comment Share on other sites More sharing options...
join Posted October 12, 2008 Share Posted October 12, 2008 try my topic, works like a charmhttp://www.autoitscript.com/forum/index.ph...=random+numbers 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