PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
tecton
Forum Newbie
Posts: 22 Joined: Sat Dec 20, 2003 1:58 am
Contact:
Post
by tecton » Wed Sep 01, 2004 9:45 pm
kind of a strange request
i need to figure out how to obtain multiple random text strings from a single page display...
all the random text scripts i can find only run once, i need something that i can run 5-6-7-8 times on a single page...each time producing a new random string
any ideas?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Sep 01, 2004 9:54 pm
single page display of.. html, plain text, what?
new random string of any line? or just random offsets into the file? please explain a bit more.
tecton
Forum Newbie
Posts: 22 Joined: Sat Dec 20, 2003 1:58 am
Contact:
Post
by tecton » Wed Sep 01, 2004 9:58 pm
html
i need a new random number to be created each time i call for it in a single page
lets say i call $random
$random = 25
if i call random again, i will have 2 "25"'s
i dont want that
i want to be able to call it multiple times, and get different results each time
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Sep 01, 2004 10:02 pm
[php_man]rand[/php_man] or [php_man]mt_rand[/php_man] can do this..
tecton
Forum Newbie
Posts: 22 Joined: Sat Dec 20, 2003 1:58 am
Contact:
Post
by tecton » Wed Sep 01, 2004 10:05 pm
this might work
but i will need it to only pick between 2 numbers
1 and 0
1 character long
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Sep 01, 2004 10:10 pm
it's not likely to loop within a short period of time unless it's called a LOT.. you can use those 2 functions with [php_man]uniqid[/php_man] to get a nice big random if you need it closer to truely random.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Sep 01, 2004 10:13 pm
if you just want to choose between 1 and 0 or whatever boolean level thing I do this all the time:
tells you whether mt_rand returned an even or odd number
(even = 0)
I use mt_rand because it has a MUCH longer (2^19937-1) repeat period than rand and 4 times faster..
tecton
Forum Newbie
Posts: 22 Joined: Sat Dec 20, 2003 1:58 am
Contact:
Post
by tecton » Wed Sep 01, 2004 10:17 pm
but can i run that multiple times in a single page without returning the same result
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Sep 01, 2004 10:21 pm
correct.. if you want to keep that result throughout the page, just save it into a variable.
tecton
Forum Newbie
Posts: 22 Joined: Sat Dec 20, 2003 1:58 am
Contact:
Post
by tecton » Wed Sep 01, 2004 10:24 pm
hehe
i dont, thats the point
i want a new random number, each time i call the script, possibly multiple times on a single page
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Sep 01, 2004 10:29 pm
then just call [php_man]mt_rand[/php_man] or whatever every time you want it. what's the big deal?
tecton
Forum Newbie
Posts: 22 Joined: Sat Dec 20, 2003 1:58 am
Contact:
Post
by tecton » Wed Sep 01, 2004 10:35 pm
the big deal is i dont know how to call that
2 numbers
0 or 1
then use that to call something else
like 0.gif
1.gif
i need it in variable form i would say for that....this is just getting more and more out of my hands
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Sep 01, 2004 10:37 pm