Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 03-16-2009, 05:20 AM   #1
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,372
php question, best way for random numbers?

Whats the best way for random number generation?

this is what im using now

Code:
<?
mt_srand ((double) microtime() * 1000000);
$random = mt_rand(1,100);
echo $random;
?>
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-16-2009, 05:21 AM   #2
HorseShit
Too lazy to set a custom title
 
Join Date: Dec 2004
Posts: 17,513
not sure but im sure our channel coders will know
HorseShit is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-16-2009, 05:29 AM   #3
grumpy
Too lazy to set a custom title
 
grumpy's Avatar
 
Join Date: Jan 2002
Location: Holland
Posts: 9,870
you dont need the mt_srand ((double) microtime() * 1000000);
Its build in in the mt_rand
__________________
Don't let greediness blur your vision | You gotta let some shit slide
icq - 441-456-888
grumpy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-16-2009, 05:45 AM   #4
Libertine
sex dwarf
 
Libertine's Avatar
 
Join Date: May 2002
Posts: 17,860
Quote:
Originally Posted by grumpy View Post
you dont need the mt_srand ((double) microtime() * 1000000);
Its build in in the mt_rand
Yep. As of 4.2, seeding is no longer needed, if I recall correctly.

mt_rand() will do for most purposes, but if you need pseudo-random data for purposes related to cryptography, keep in mind that mt_rand uses a mersenne twister, which is rather weak. So, in those cases, getting your pseudo-random data from /dev/urandom is a better option.
__________________
/(bb|[^b]{2})/
Libertine is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-16-2009, 05:47 AM   #5
leek
Confirmed User
 
leek's Avatar
 
Join Date: May 2008
Location: Charlotte, NC
Posts: 342
Quote:
Note: As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically.
RTFM
leek is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-16-2009, 05:50 AM   #6
Brujah
Beer Money Baron
 
Brujah's Avatar
 
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
I believe that you don't really need to use mt_srand with php 5.2.1+
You could use uniqid as a seed, or data from /dev/random
__________________
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-16-2009, 05:51 AM   #7
Brujah
Beer Money Baron
 
Brujah's Avatar
 
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
Quote:
Originally Posted by grumpy View Post
you dont need the mt_srand ((double) microtime() * 1000000);
Its build in in the mt_rand
True, but there was a fuss about it being insecure until 5.2.1+ I think
__________________
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-16-2009, 06:30 AM   #8
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,372
im just getting a random number for random image headers, have 10 headers, want to rotate through them
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-16-2009, 06:53 AM   #9
Libertine
sex dwarf
 
Libertine's Avatar
 
Join Date: May 2002
Posts: 17,860
Quote:
Originally Posted by fris View Post
im just getting a random number for random image headers, have 10 headers, want to rotate through them
mt_rand will do fine, then.

The other stuff only comes into play when dealing with things where security is an issue, like when a forgotten admin password of a site gets reset on request (which actually was a security hole in Joomla and WP).
__________________
/(bb|[^b]{2})/
Libertine is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-16-2009, 07:49 AM   #10
yuu.design
Too lazy to set a custom title
 
yuu.design's Avatar
 
Industry Role:
Join Date: Mar 2006
Location: Argentina
Posts: 25,924
Quote:
Originally Posted by fris View Post
im just getting a random number for random image headers, have 10 headers, want to rotate through them
<?php
$image = rand(1,10);

echo "<img src=\"$image.jpg\" width=\"\" height=\"\" alt=\"\" />";

?>

__________________
Beautiful And Usable Web Design Creations For The Adult Industry Since 2003
I'm Yuu, Designer and Content Producer

Paysites - Affiliate Programs - Dating & Cam Sites - Mainstream Projects - Tube Sites - Banners - Wordpress Themes - NATs integration - Landing Pages

Check my Portfolio and Content Production Offers
yuu.design is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-16-2009, 08:49 AM   #11
Killswitch - BANNED FOR LIFE
Guest
 
Posts: n/a
Like above, rand() will work fine for what you need.
  Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.