How Can I Generate Unique Random Num Wt Php Oop - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › How Can I Generate Unique Random Num Wt Php Oop (1572 Views)
| How Can I Generate Unique Random Num Wt Php Oop by cr80vity(op): 8:44pm On Apr 25, 2017 |
good evening... please i want to generate a unique random number for each registered user.. how can i write a php oop code to generate it? the random code will Start with 3 alphabets, end with 2 alphabets and 4 numbers in between also, after generating it, how will I make it store in mysql database? its a project given to me, please help me out guys... |
| Re: How Can I Generate Unique Random Num Wt Php Oop by yorex2011: 7:48am On Apr 26, 2017 |
![]() Dude... Read up on generating random strings in php na.. You can use arrays or substr function for the alphabets, rand function for the numbers |
| Re: How Can I Generate Unique Random Num Wt Php Oop by cr80vity(op): 9:09am On Apr 26, 2017 |
yorex2011:m learner so if I know I won't come here for help.... how can I let the code put 4 numbers in between the alphabets and how can I store it in database |
| Re: How Can I Generate Unique Random Num Wt Php Oop by teampregar(m): 8:21pm On Apr 26, 2017 |
A better approach will be to use only numbers instead. Because if you use two first alphabets, the probability of uniqueness will be a-z.. And for the middle numbers will only be unique to its placeholder domain(ie, 4000056 can only accomodate 1000000 - 4000056)... If you are on facebook try to download a photo on your news feed, it will have a file name like : 1508866654_5524343664_55600545_n.jpg . The numbers in this name was generated by a unique id generation system built by facebook..Twitter has open-sourced theirs with an API(search google for snowflake). I have also built one(Want to use it for a project) but it is copyrighted for now. |
| Re: How Can I Generate Unique Random Num Wt Php Oop by cr80vity(op): 2:38pm On Apr 27, 2017 |
pls guys, it will just be like a plate number |
| Re: How Can I Generate Unique Random Num Wt Php Oop by directonpc(m): 7:50pm On Apr 27, 2017 |
Nairaland is popular for this! You hardly get answers here. I ain't doing better sha since a I am not in the mode of providing answers. My advise search stackoverflow.com if you are unable to find an answer you can ask them there. |
| Re: How Can I Generate Unique Random Num Wt Php Oop by bet9ja(m): 7:25am On Apr 28, 2017 |
directonpc:Majority of nairaland programmers reinvent the wheel. |
| Re: How Can I Generate Unique Random Num Wt Php Oop by directonpc(m): 9:14am On Apr 28, 2017 |
bet9ja:correct, you have summarized it. |
| Re: How Can I Generate Unique Random Num Wt Php Oop by yorex2011: 10:02am On Apr 30, 2017 |
Function generateId ( ) { $rand_four_digits = rand(1000, 9999); $aphabets = array("A",.... "Z" ; //list A to Z//you generate a random alphabet using $random_index = rand(0, 25); $random_alphabet = $alphabets[$random_index] ; //you can then generate more and concatenate $generated_id ="whatever" ; return $your_generated_id; } I'd suggest doing it in at least 3 different ways so you can learn |
How Can I Generate Money Using Facebook? • Who Is Good In Php Oop And Lives In Kano State? • After 5 Months Of Learning OOP In Visual C#-here Is A Little Project I Made. • 2 • 3 • 4
Someone Fluent In Both Python And MATLAB Needed • Where Can I Get A Recent Nigerian Stock Exchange Historical Stock Price Dataset • Verified USA Admob + Verified Payoneer Account For Sale

; //list A to Z