Tags
PHP
Asked 2 years ago
14 Jul 2021
Views 269
Ariane

Ariane posted

How can I generate a number that never be the same again in php

How can I generate a number that never be the same again in php
it should be unique in life time
i want to use it as unique identifier
shyam

shyam
answered Oct 26 '21 00:00

mulitpling uniqid () and rand () can be genreate 16 digit unique number each time

<?php 
 
echo uniqid()*rand();
?>
jignesh

jignesh
answered Oct 26 '21 00:00

I tried an crazy way to create a random string with numbers and characters.

echo uniqid(rand(rand(),rand()));

or another crazy way but it only refresh last some character.

echo uniqid(rand(uniqid(rand())));

debugger

debugger
answered Oct 26 '21 00:00

use random_int alternative of the rand () function , but we need to provide the min and max range to the random_int .

uniqid( random_int(1,1000000000000000));
ajamil

ajamil
answered Oct 26 '21 00:00

rand() generate random number in php
we can make a unique id from random generated number.

echo uniqid(rand());
jabber

jabber
answered Oct 26 '21 00:00

uniqid() can also create the unique code also .
Post Answer