smc Posted January 29, 2007 Share Posted January 29, 2007 Hello,I'd like to make a random article id that can never re-occur. I thought about doing auto-increment in MySQL but I'd rather not give away exactly how many articles are in the DB, just seems unprofessional.Thanks for any light you can shed on the issue!Thanks Link to comment https://forums.phpfreaks.com/topic/36241-solved-generating-completly-random-numbers/ Share on other sites More sharing options...
HuggieBear Posted January 29, 2007 Share Posted January 29, 2007 How about make it auto-increment but start it on something random like 4932.Nobody will be any the wiser then![code]ALTER TABLE table_name ADD column_name INT UNSIGNED NOT NULL AUTO_INCREMENT=4932[/code]That should do it.RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/36241-solved-generating-completly-random-numbers/#findComment-172254 Share on other sites More sharing options...
boo_lolly Posted January 29, 2007 Share Posted January 29, 2007 how many characters do you want it to be? a quick/simple example would be:[code]<?php $salt = ""; $rand = rand(0, 9); $length = 10; for($i = 0; $i < $length; $i++){ $salt .= $rand; } echo $salt;?>[/code]untested. Link to comment https://forums.phpfreaks.com/topic/36241-solved-generating-completly-random-numbers/#findComment-172255 Share on other sites More sharing options...
Jessica Posted January 29, 2007 Share Posted January 29, 2007 or use the current timestamp. That's what a legacy program I once had to maintain did. Seriously, no one will care but you... Link to comment https://forums.phpfreaks.com/topic/36241-solved-generating-completly-random-numbers/#findComment-172256 Share on other sites More sharing options...
JasonLewis Posted January 29, 2007 Share Posted January 29, 2007 i was going to suggest timestamp to. just use time() or microtime() except microtime() has a decimal in it, but that could be removed. Link to comment https://forums.phpfreaks.com/topic/36241-solved-generating-completly-random-numbers/#findComment-172259 Share on other sites More sharing options...
HuggieBear Posted January 29, 2007 Share Posted January 29, 2007 [quote author=ProjectFear link=topic=124605.msg516537#msg516537 date=1170111884]i was going to suggest timestamp to. just use time()[/quote]If you're going with timestamp, then just use mysql's now() function, don't worry about PHP's time() or microtime() functions at all.INSERT INTO table_name (unique_id) VALUES (now())RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/36241-solved-generating-completly-random-numbers/#findComment-172266 Share on other sites More sharing options...
smc Posted January 29, 2007 Author Share Posted January 29, 2007 I saw this somewhere, would this work?md5(uniqid(rand())) Link to comment https://forums.phpfreaks.com/topic/36241-solved-generating-completly-random-numbers/#findComment-172269 Share on other sites More sharing options...
Jessica Posted January 29, 2007 Share Posted January 29, 2007 That's kind of overkill. Plus md5 can collide. Link to comment https://forums.phpfreaks.com/topic/36241-solved-generating-completly-random-numbers/#findComment-172271 Share on other sites More sharing options...
JasonLewis Posted January 29, 2007 Share Posted January 29, 2007 if your going to use md5 just insert the id as like, 1, 2, 3, 4 etc. Then when retriving it and using it md5() the variable. It would be easier to configure your DB in the future. Link to comment https://forums.phpfreaks.com/topic/36241-solved-generating-completly-random-numbers/#findComment-172275 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.