RussF wrote: ↑30 Mar 2023, 11:19
Why not just use the digits 0 - 9. That will give you 10 unique, single-digit numbers. If you really need 1 - 10, just add 1 to the value in your array whenever you use it further on.
Russ
Hi Russ,
Thanks for your reply. Unfortunately that won't work I really need the number 1 - 10 in this case.
I just started practicing with AHKv2 and I'm writing a gui which my daughters could use to practice
multiplication. I've gotten it working so far, but I would also like them to practice them in random order
so I'd like to add a button to switch from ordered to random. So far my gui looks like this:
Smile_ wrote:
I think it could have something to do that the number 1 is also in 10 ??
If the 1 was written before the 10 will be OK I guess, as an alternative maybe you should surround the number between two spaces and look for it in
ArrayContent var with it spaces, but still that is not the best thing to do.
Imagine that you are trying to pick up randomly 10 numbered balls (1 - 10) out of a box, each one you take out should be removed from the box which you didn't do with
N := Random(1, 10) always assuming that all the balls are in the box, so what happen when the random results lead to a ball that is already taken? I think that is not necessary to do, because that will lead to unnecessary iterations.
Yes you are completely correct. After reading your comment yesterday I started thinking about how I could pick one number from the ordered array and put
in in the other and deleting it from the first. I came up with the code posted below, which is quite similar to what
@boiler posted
@boiler
Thank you so much for your examples. I didn't know you could sort numbers in a variable like that, very helpfull.
My version:
Code: Select all
Times := 10
ArrayContent := ""
RandomCounter := []
OrderedCounter := []
loop Times ; create an array of ordered numbers
OrderedCounter.Push(A_Index)
loop Times
{
MyNumber := Random(1, OrderedCounter.Length)
RandomCounter.Push(OrderedCounter[MyNumber])
OrderedCounter.RemoveAt(MyNumber)
}
loop Times
ArrayContent .= RandomCounter[A_Index] "-"
MsgBox Substr(ArrayContent, 1, -1)