1
How to generate random numbers starting from 00000 to 99999 without repetition using Mysql only, numbers cannot start in 000, anyone has any idea how I can do this?
1
How to generate random numbers starting from 00000 to 99999 without repetition using Mysql only, numbers cannot start in 000, anyone has any idea how I can do this?
1
Good morning Bruno. I think you can use this here:
select FLOOR(RAND() * 99999)
Or rather:
BEGIN
DECLARE valorRand bigint;
set valorRand = select FLOOR(RAND() * 99999);
if exists (select * from tabela where coluna = valorRand) then
call meuRandon();
end if
return valorRand;
then you have to see how many times it can be repeated.
Forehead in your mysql
And how do you make sure this doesn’t get repeated?
@Maniero does not guarantee. rsrsrs
@cpll thanks for the force, but there can be no repetitions.
@Bruno Richart, you need to shape the idea better about its rules and needs, but I tried to make the function, only return a value when it does not yet exist. I did recursive, but the idea can be improved and done in functions.
@cpll yes true, but helped a lot I’ve managed, thank you very much.
Browser other questions tagged php mysql
You are not signed in. Login or sign up in order to post.
Search about the function
rand()
. With it you can already have an idea of how to do.– Woss
What is the limit? How many random numbers?
– Andrei Coelho
What do you mean, you can’t start at 1000? Numbers never start at 0. What you want is 100 forward so?
– Maniero
I think he meant bigger than 100 (00100)
– user60252
@Leocaracciolo is, I thought one thing and wrote another, I think it’s this, but I want him to confirm, it’s weird.
– Maniero
Maybe this will help https://stackoverflow.com/questions/11680025/how-to-generate-random-number-without-repeat-in-database-using-php/40549385#40549385 please amend
WHERE my_number IS NOT NULL)
forWHERE my_number >100)
– user60252
For use with INSERT or SELECT?
– Guilherme Nascimento