Finally found a solution for non repeating random numbers

'draw 10 numbers out of 10 without repeating numbers
'maybe dirty coding, but it seems to work :slight_smile:

Dim i as Integer
Dim j as Integer
Dim Rn(10) as Integer

Rn(1) = Rnd * 10 + 1

For i = 2 to 10

Rn(i) = Rnd * 10 + 1

For j = 1 to i-1
If Rn(i) = Rn(j) then
Rn(i) = Rnd * 10 + 1
i = i-1

End if

next
next

'for i = 1 to 10
’
'Label1(i).Text = Rn(i).totext
’
'next
’ Please have a good day, Rolf :slight_smile:

A simpler solution would be to fill the array with the numbers 1 to 10 and then shuffle the array.

https://documentation.xojo.com/api/language/shuffle.html

5 Likes
Var myArr() As Integer
For X As Integer = 1 To 10
  myArr.Add X
Next
myArr.Shuffle

Just because a short example/snippet is always welcome :slight_smile:

3 Likes

Thank you for your replies, Kevin and Sascha
:slightly_smiling_face:
I did not know about the shuffle until now…
Yours, Rolf

1 Like