HOW TO GENERATE RANDOM NUMBERS SAVED IN A TEXT FILE
Moderator: General Moderators
HOW TO GENERATE RANDOM NUMBERS SAVED IN A TEXT FILE
How can I generate numbers saved in a text file and delete it after generation to avoid the same number being generated again. This numbers will be generated on demand.. For example can generate 1 or 2 or 3 to 10 numbers based on selection.. And those numbers must be deleted after generation.. Please i need help
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: HOW TO GENERATE RANDOM NUMBERS SAVED IN A TEXT FILE
It is not clear whether you want to generate unique numbers or generate unique random numbers. Those are two different things.
To generate unique numbers, just create a file with a counter in it. If you want numbers, start with the counter and generate as many sequential numbers as you need. Save the value of the next available number to the counter file.
For unique random numbers, you might want both a counter file and a file with a set of randomish numbers. For example, start with the number in the counter file and generate 1000 sequential numbers, shuffle them and save them to a file. Pull numbers out of the file, deleting the numbers as you remove them. When the file is empty, generate another 1000 random numbers starting with the next counter value.
To generate unique numbers, just create a file with a counter in it. If you want numbers, start with the counter and generate as many sequential numbers as you need. Save the value of the next available number to the counter file.
For unique random numbers, you might want both a counter file and a file with a set of randomish numbers. For example, start with the number in the counter file and generate 1000 sequential numbers, shuffle them and save them to a file. Pull numbers out of the file, deleting the numbers as you remove them. When the file is empty, generate another 1000 random numbers starting with the next counter value.
(#10850)