I used random function in my code however i dont know how could i prevent repetition.Also i read another questions about this subject but i dont want to use "Shuffle".
Thanks for all help and clues.
I used random function in my code however i dont know how could i prevent repetition.Also i read another questions about this subject but i dont want to use "Shuffle".
Thanks for all help and clues.
By definition, randomness includes de possibility of repetition, because every calculated random number is independent from the previous ones.
You should update your logic to save the generated numbers into a list for example, and check if the number is contained in such list. If it is, loop until it generates a new one.
You could also add a maximum loop count to avoid the program hanging forever.
You should follow below algorithmic steps to get solution for requirement:
Declare auxiliary container to store your ATN numbers, here Set is appropriate as Set do not allow duplicate entries.
Generate random number.
Check if this is presented in your auxiliary container?
Yes then go to step 2.
No then save to auxiliary storage.
Do your business logic.
Set doesn't allow duplicates