I want to have a random serial created on my website everytime someone visits.
License key generator free download - Mirrakey License Key Generator, Serial Key Generator, CD Key Generator, and many more programs.
The format of the serial should be XXXXX-XXXXX-XXXXX-XXXXX.
X represents a random number or capital letter.
Unfortunately I have no idea how to do this. Could anybody please help me out?
So for example the random serial output could be: 3WT4A-NB34O-JU87P-B3UHS
Thanks a lot!
7 Answers
There are most certainly better ways of doing it, but this is the first that jumps to mind:
05/26/13 Edit: It's advised to keep the Count function outside of the loop. The reason for this is that you don't want to expend the extra clock cycles running this function through each iteration when you can simply run it once.
maiorano84maiorano84Another approach is to calculate the four segments as random numbers in base 36.
salathesalatheReimage License Key Generator
The most straightforward solution would be something like this.
Sample output:
There's a bunch of ways to approach this. One simple one is:
There are better ways to generate random strings then this but this would give you the basic functionality you're looking for.
John CondeJohn CondeIf you want to use this serial just because of uniqueness - you could also try to use UUID v4, as described in one of answers here: PHP function to generate v4 UUID
There a lot of such answers at SO: https://stackoverflow.com/a/4356295/1091195
You can use the random string generator mentioned there, either you use it once to get a 20 letter string then insert dashes, or you can call it 4 times for 5 letter and concat the results.