24.02.2019, 13:05
If you want a minimum value, then you have to start at that value and generate only how much is missing from your max.
In your code it would be:
I would suggest saving these values somewhere so that you could edit them in an easier manner.
E.g.
That way if you want to change the phone number limit to something else, all you need to do is change the defines.
If you want to create unique phone number, you will have to use some place to store the current numbers, like a MySQL database. Store the phone numbers along with user data and after generating a new number, query to see if it already exists. I think you could do it directly in the database and then just fetch the number but I haven't had to do it and don't want mess up with it.
In your code it would be:
Код:
new rand = 10_000 + random(90_000);
E.g.
Код:
#define MAX_PHONE_NUMBER 100_000 //along with your other defines/globals/whatever #define MIN_PHONE_NUMBER 10_000 new rand = MIN_PHONE_NUMBER + random(MAX_PHONE_NUMBER - MIN_PHONE_NUMBER);
If you want to create unique phone number, you will have to use some place to store the current numbers, like a MySQL database. Store the phone numbers along with user data and after generating a new number, query to see if it already exists. I think you could do it directly in the database and then just fetch the number but I haven't had to do it and don't want mess up with it.