Jump to content


Photo

Creating a random number generator


  • Please log in to reply
2 replies to this topic

#1 bobsci

bobsci
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 29 November 2003 - 02:10 AM

Hi all...

I just wanted to do something really simple... i want php to echo 7 random numbers ie: 4528765. using the values 123456789. How do i go about it? thanx
"...The Best way to blow up the libary is to put some C4 around the second last column near the periodicals..." - My international studies teacher

#2 Deadmeat

Deadmeat
  • Members
  • PipPip
  • Member
  • 20 posts
  • Locationva

Posted 29 November 2003 - 03:25 AM

my guess is use mt_rand(min, max)

either use mt_rand() for each of the 7 digits, then combine them together, or use 1 mt_rand() for the whole thing (ie. mt_rand(1000000,9999999), if it allows numbers that large). I\'m a n00b myself, so don\'t assume this is the best way, because most likely it isnt. This should work though:

[php:1:c904f12a77]<?php
$array = array(mt_rand(1, 9), mt_rand(1, 9), mt_rand(1, 9), mt_rand(1, 9), mt_rand(1, 9), mt_rand(1, 9), mt_rand(1, 9));
$random = implode(\"\",$array);
echo $random;
?>[/php:1:c904f12a77]
Free Photoshop Tutorials[br]TutorialMan.com[br]---------------------------[br]Need Webspace thats cheap and reliable?[br]Quik-Online.org

#3 bobsci

bobsci
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 29 November 2003 - 05:07 AM

That was the first guess i had as well but i need something more effcient
"...The Best way to blow up the libary is to put some C4 around the second last column near the periodicals..." - My international studies teacher




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users