Answered by:
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
Answers

Hello Eamon,
Here is my answer:
For i = 1 To 6 number[i]=Math.GetRandomNumber(100) For a = 1 To i1 While number[i]=number[a] number[i]=Math.GetRandomNumber(100) EndWhile EndFor EndFor For i = 1 To 6 TextWindow.WriteLine(number[i]) EndFor
Hope it can help you.
Best Wishes & Regards!
 Proposed as answer by ThaelmannPioniere Monday, April 6, 2020 4:55 AM
 Edited by ThaelmannPioniere Monday, April 6, 2020 5:16 AM
 Marked as answer by EamonSharma Monday, April 6, 2020 11:38 PM
All replies

Hello Eamon,
Here is my answer:
For i = 1 To 6 number[i]=Math.GetRandomNumber(100) For a = 1 To i1 While number[i]=number[a] number[i]=Math.GetRandomNumber(100) EndWhile EndFor EndFor For i = 1 To 6 TextWindow.WriteLine(number[i]) EndFor
Hope it can help you.
Best Wishes & Regards!
 Proposed as answer by ThaelmannPioniere Monday, April 6, 2020 4:55 AM
 Edited by ThaelmannPioniere Monday, April 6, 2020 5:16 AM
 Marked as answer by EamonSharma Monday, April 6, 2020 11:38 PM




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!

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
 Proposed as answer by ThaelmannPioniere Monday, April 6, 2020 11:36 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 Eddy Abts Monday, April 6, 2020 7:38 PM
