NameSilo

2 piece randomisation script.

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

PoorDoggie

Soon to be RICHdoggie!VIP Member
Impact
18
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
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
PHP:
if(rand(0,1) == 0)
    echo $str1;
else
    echo $str2;

Should work for just 2 strings
 
0
Close
that simple huh?

Thanks a lot! :)
 
0
Close
PHP:
echo (mt_rand(0, 1) == 0) ? $str1 : $str2;

Cleaner :p :) Sorry, had to :guilty:
 
0
Close
:lol: what is the difference between mt_rand and rand?
 
0
Close
It is 4 times faster.
 
0
Close
SecondVersion said:
PHP:
echo (mt_rand(0, 1) == 0) ? $str1 : $str2;

Cleaner :p :) Sorry, had to :guilty:

it maybe cleaner but harder to read.
 
0
Close
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
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back