 |
Results from the most recent live auction are here.
22 members in the live chat room. Join Chat!
| |
06-01-2006, 02:11 PM
|
· #1 | | Soon to be RICHdoggie! Name: Tom Location: UK Join Date: Jan 2005
Posts: 2,390
NP$: 300.50 ( Donate)
| 2 piece randomisation script. Hi,
I need to write a script that will show a string 50% of the time and another string the other 50% of the time, but not always one after the other.
ie: I don't want someone to be able to anticipate which one is coming next.
so, can anyone help me randomise two strings, lets call them str1 and str2? I just don't know very much about randomisation. (well, nothing in fact)
They can't be bias though, the probability of either showing up should be 50%.
Thanks
Tom |
| |
06-01-2006, 02:23 PM
|
· #2 | | NamePros Member | PHP Code: if(rand(0,1) == 0)
echo $str1;
else
echo $str2;
Should work for just 2 strings |
| |
06-01-2006, 02:26 PM
|
· #3 | | Soon to be RICHdoggie! Name: Tom Location: UK Join Date: Jan 2005
Posts: 2,390
NP$: 300.50 ( Donate)
| that simple huh?
Thanks a lot!  |
| |
06-01-2006, 03:40 PM
|
· #4 | | while ($awake){ code(); } Name: Eric Location: Kentucky Join Date: Mar 2005
Posts: 4,268
NP$: 1152.00 ( Donate)
| PHP Code: echo (mt_rand(0, 1) == 0) ? $str1 : $str2;
Cleaner  Sorry, had to  |
| |
06-01-2006, 04:04 PM
|
· #5 | | Soon to be RICHdoggie! Name: Tom Location: UK Join Date: Jan 2005
Posts: 2,390
NP$: 300.50 ( Donate)
|  what is the difference between mt_rand and rand? |
| |
06-01-2006, 06:25 PM
|
· #6 | | Buy my domains. Name: Dan Join Date: Feb 2006
Posts: 2,801
NP$: 54.00 ( Donate)
| It is 4 times faster. |
| |
06-02-2006, 12:40 AM
|
· #7 | | NamePros Staff Name: Peter Location: Scotland Join Date: Nov 2003
Posts: 4,337
NP$: 2039.40 ( Donate)
|
it maybe cleaner but harder to read. |
| |
06-02-2006, 07:53 AM
|
· #8 | | Soon to be RICHdoggie! Name: Tom Location: UK Join Date: Jan 2005
Posts: 2,390
NP$: 300.50 ( Donate)
| not really, but the point is that I define a variable before and then if rand(1,0)==0 then I change it, so I can't do it the second way!
Thanks
Tom |
| |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | |