Page 1 of 1

multiple random text

Posted: Wed Sep 01, 2004 9:45 pm
by tecton
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?

Posted: Wed Sep 01, 2004 9:54 pm
by feyd
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.

Posted: Wed Sep 01, 2004 9:58 pm
by tecton
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

Posted: Wed Sep 01, 2004 10:02 pm
by feyd
[php_man]rand[/php_man] or [php_man]mt_rand[/php_man] can do this..

Posted: Wed Sep 01, 2004 10:05 pm
by tecton
this might work

but i will need it to only pick between 2 numbers

1 and 0

1 character long

Posted: Wed Sep 01, 2004 10:10 pm
by feyd
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.

Posted: Wed Sep 01, 2004 10:13 pm
by feyd
if you just want to choose between 1 and 0 or whatever boolean level thing I do this all the time:

Code: Select all

$choice = mt_rand() % 2
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..

Posted: Wed Sep 01, 2004 10:17 pm
by tecton
but can i run that multiple times in a single page without returning the same result

Posted: Wed Sep 01, 2004 10:21 pm
by feyd
correct.. if you want to keep that result throughout the page, just save it into a variable.

Posted: Wed Sep 01, 2004 10:24 pm
by tecton
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
8)

Posted: Wed Sep 01, 2004 10:29 pm
by feyd
then just call [php_man]mt_rand[/php_man] or whatever every time you want it. what's the big deal?

Posted: Wed Sep 01, 2004 10:35 pm
by tecton
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

Posted: Wed Sep 01, 2004 10:37 pm
by feyd

Code: Select all

echo (mt_rand() % 2) . '.gif';
:?