HOW TO GENERATE RANDOM NUMBERS SAVED IN A TEXT FILE

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Kingo4luv
Forum Newbie
Posts: 1
Joined: Wed Sep 23, 2015 3:54 pm

HOW TO GENERATE RANDOM NUMBERS SAVED IN A TEXT FILE

Post by Kingo4luv »

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
User avatar
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

Post by Christopher »

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.
(#10850)
Post Reply