Welcome to WebmasterWorld Guest from 220.127.116.11
Using PHP I want to generate a unique random 14 digits HARD-TO-GUESS number that will fill about 100000 rows in a MySQL table. It's easy to use the rand function of PHP to generate a random unique 14 digits number. The problem actually lies in the word HARD-TO-GUESS.
I think HARD-TO-GUESS actually means that for every single number there must be at least 3 nonadjacent digits different than any other number previously generated or stored.
1) 11111111111111 accepted
2) 12112112111111 accepted
3) 12112112121212 accepted
4) 11111111111110 not accepted, only 1 different
5) 11111111111122 not accepted, only 2 and adjacent
6) 21111111111122 not accepted, 2 digits adjacent
7) 11111111111222 not accepted, 3 digits adjacent
I know it's a complex task, but I think it can be a very helpful application for everybody.
A 14 digit number is so big that few numbers should have the 3 adjacent number problem.
There are several API's online that give you access to true random number generators. Look for one of those - that will allow you to generate truely random numbers less likely to meet your reject criteria.
if you want to enforce some rules then what you are trying to do is actually reduce the randomness and enforce some type of rules
you could generate it number by number and do tests as you go
you could just use regex to test for the specific rules you would like to enforce
it's not overly complicated, you just need to decide on your rules, generate a number, if it passes the rules insert it, if not throw it away and start over
Actually, I guess some of the rules can be made with regex not all of them. The problem is I'm newbie to regex..
I think either it is seeded properly or not, I have to check the results with some rules that don't make similar numbers to be stored. I've searched the net but I think that most of the results were not very in depth.
This is exactly what I want to do: Reduce the randomness to make it less predictable. Anyway, I will need help with regex.
New rules for validating a single number:
1) Maximum repetition for a typical number is 3.
2) Maximum adjacent repetition for a typical number is 2.
3) Most significant digit must not start with 0.
Rules for validating a number with respect to previously generated:
1) At least 3 nonadjacent digits must be different from any other number. Examples are in my first post.
2) The difference between any pair of generated number must not be multiple of 10, (i.e, 10,100,1000,10000,..,ect).
do you have ideas how to address those?
you don't necessarily need regex, you could also generate the number 1 digit at a time, though this isn't the only answer
take a shot and see what you come up with