# Repeating Numbers • ### Question

• Hey, I need a snip of code for a program I making that has something to do with a lottery. But one premise of the game is that is generates 6 random numbers(max of 100) and none of those numbers cannot repeat. I cant figure out how to program a part that can detect a repeated number and change it to another. Any help?

Thanks.

Eamon

Monday, April 6, 2020 4:21 AM

• Hello Eamon,

```For i = 1 To 6
number[i]=Math.GetRandomNumber(100)
For a = 1 To i-1
While number[i]=number[a]
number[i]=Math.GetRandomNumber(100)
EndWhile
EndFor
EndFor
For i = 1 To 6
TextWindow.WriteLine(number[i])
EndFor ```

Best Wishes & Regards!

Monday, April 6, 2020 4:55 AM

### All replies

• Hello Eamon,

```For i = 1 To 6
number[i]=Math.GetRandomNumber(100)
For a = 1 To i-1
While number[i]=number[a]
number[i]=Math.GetRandomNumber(100)
EndWhile
EndFor
EndFor
For i = 1 To 6
TextWindow.WriteLine(number[i])
EndFor ```

Best Wishes & Regards!

Monday, April 6, 2020 4:55 AM
• Thank you, it did :)

Eamon

Monday, April 6, 2020 5:37 AM
• Hi Eamon,

I'm happy to hear it! If there aren't any questions or problems, can you please mark it as answer?

Best Regards & Thanks.

p.s. I think maybe have another good answer. Who will make it?

Monday, April 6, 2020 5:44 AM
• Instead of the "For a" loop, you can use   If Array.ContainsValue(..)

Jan [ WhTurner ] The Netherlands

Monday, April 6, 2020 10:00 AM
• Hallo Jan,

OK, I made a work with "Array.ContainsValue()".

```For i = 1 To 6
number[i]=Math.GetRandomNumber(6)
While Array.ContainsValue(othernumber,number[i])
number[i]=Math.GetRandomNumber(6)
EndWhile
othernumber[i]=number[i]
EndFor
For i = 1 To 6
TextWindow.WriteLine(number[i])
EndFor ```

Thanks & Best Regards!

Monday, April 6, 2020 10:55 AM
• No need to use another array, just a variable
```For i = 1 To 6
num=Math.GetRandomNumber(6)
While Array.ContainsValue(number,num)
num=Math.GetRandomNumber(6)
EndWhile
number[i]=num
EndFor
For i = 1 To 6
TextWindow.WriteLine(number[i])
EndFor ```

Jan [ WhTurner ] The Netherlands

Monday, April 6, 2020 11:25 AM
• The question is not clear for me ... if he is asking 6 random numbers between 1 and 100 it's easy to adapt the interesting program from Jan. ( in copy)

Modifying the program to keep the first number in a file, and once we start the program again (next day ?) to keep also the second number, etc  to avoid having the same result, - but i don't know if it's the question.

The numbers are pseudo random - however small basic is not providing the seednumber. In real cases (at the army) they use  the emission of charged particles from the sun to calculate a random list and its copy - one to generate the encrypted text and the copy to decrypt.

It's possible to write yourself a pseudo random generator based on the remainderslists with prime numbers , it's fun but still another topic ?

```max=99
numbers=6
For i = 1 To Max
num=Math.GetRandomNumber(Max)
While Array.ContainsValue(number,num)
num=Math.GetRandomNumber(Max)
EndWhile
number[i]=num
EndFor
For i = 1 To numbers
TextWindow.WriteLine(number[i])
EndFor ```

Jan's program

• Edited by Monday, April 6, 2020 7:38 PM
Monday, April 6, 2020 1:12 PM
• Hey I found a program with random numbers  : JFB378-0

from Pappa Lapub (Richard L. Mueller)

searching how to syntax  ldcall.function2

Wednesday, April 8, 2020 6:17 AM