Answer the question
In order to leave comments, you need to log in
How to create a unique random value?
There is an online store in which an article from 100000 to 999999 is made through random.
The task, when adding a new product, is to automatically generate the next value of the article through random, but so that it is unique (only numbers).
How to implement this?
Answer the question
In order to leave comments, you need to log in
Wait, why are you not satisfied with AUTO_INCREMENT in sql?
You will have to check with the base all the time whether there is one or not, the best option is id Primary AUTO_INCREMENT and the countdown would be from 100000.
We generate a hash from the characteristics of the product,
if a collision occurs, we take it randomly,
if a collision occurs, see step 2.
And what AUTO_INCREMENT is not suitable? If not, then any random value can be added to it, in which case, if the random value matches, the final value will still be unique, you can also hash it from above ...
I did this in OpenCart - I took the product id and added a rand () number to it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question