Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
125
rated 0 times [  129] [ 4]  / answers: 1 / hits: 48933  / 14 Years ago, wed, february 2, 2011, 12:00:00

what's the equivalent of this function in javascript:



http://php.net/manual/en/function.uniqid.php



Basically I need to generate a random ID that looks like: a4245f54345 and starts with a alphabetic character (so I can use it as a CSS id)


More From » jquery

 Answers
8

Try this (Work in php).



$prefix = chr(rand(97,121));  
$uniqid = $prefix.uniqid(); // $uniqid = uniqid($prefix);


Try this for JavaScript::



var n = Math.floor(Math.random() * 11);
var k = Math.floor(Math.random() * 1000000);
var m = String.fromCharCode(n) + k;

[#93939] Monday, January 31, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kylee

Total Points: 60
Total Questions: 119
Total Answers: 101

Location: Bonaire
Member since Wed, Mar 29, 2023
1 Year ago
;