Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 06-11-2010, 11:43 AM   #1
dready
Confirmed User
 
dready's Avatar
 
Industry Role:
Join Date: Oct 2002
Location: Toronto, ON
Posts: 5,247
Javascript to alternate between two sources

Anyone have a code handy that would allow you to alternate between two javascript sources with each page load? Right now I have:

<SCRIPT LANGUAGE="JavaScript" SRC="1.js">
</SCRIPT>

And

<SCRIPT LANGUAGE="JavaScript" SRC="2.js">
</SCRIPT>

I'd like to only load one, and make it 50/50 between 1.js and 2.js
__________________
ICQ: 91139591
dready is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-11-2010, 11:49 AM   #2
BestXXXPorn
Confirmed User
 
BestXXXPorn's Avatar
 
Join Date: Jun 2009
Location: Asheville, NC
Posts: 2,277
you could save the last one loaded in a cookie and then keep alternating... if you don't need to it to be absolutely perfect an easier method would be to just use a random number, 1 or 2 :P
__________________
ICQ: 258-202-811 | Email: eric{at}bestxxxporn.com
BestXXXPorn is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-11-2010, 11:53 AM   #3
ProG
Confirmed User
 
Join Date: Apr 2009
Posts: 1,319
You will not get a solid 50/50 split unless you keep a count for each one. Random is usually pretty close but it could easily go 60/40 or worse, or better... it's called random for a reason.
__________________
History will be kind to me for I intend to write it.
ProG is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-11-2010, 12:08 PM   #4
AIbenjamink
Confirmed User
 
AIbenjamink's Avatar
 
Industry Role:
Join Date: Jan 2009
Posts: 420
If you want an even 50/50 split, your best implementation would most likely be accomplished server side, using PHP etc..
__________________
Benjamin : [email protected] : 405-243-447 : www.AdultInterface.com

AIbenjamink is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-11-2010, 12:11 PM   #5
quantum-x
Confirmed User
 
quantum-x's Avatar
 
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
Quote:
Originally Posted by ProG View Post
You will not get a solid 50/50 split unless you keep a count for each one. Random is usually pretty close but it could easily go 60/40 or worse, or better... it's called random for a reason.
Bullshit. Go flip a coin 1,000,000 times and tell me if it goes out to 60/40.
quantum-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-11-2010, 12:14 PM   #6
dready
Confirmed User
 
dready's Avatar
 
Industry Role:
Join Date: Oct 2002
Location: Toronto, ON
Posts: 5,247
Would this do it?

<script type="text/javascript">
<!--
var rand = Math.floor(Math.random()*2)+1;
document.write('<script type="text/javascript" src="'+rand+'.js");</script>');
</script>
__________________
ICQ: 91139591
dready is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-11-2010, 12:17 PM   #7
quantum-x
Confirmed User
 
quantum-x's Avatar
 
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
If PHP is in your reach, try:

<SCRIPT LANGUAGE="JavaScript" SRC="<?=rand(1,2)?>.js">

If not:
<script>
var oHead = document.getElementsByTagName('HEAD').item(0);
var oScript= document.createElement("script");
oScript.type = "text/javascript";
oScript.src= Math.floor ( Math.random ( ) * 2 + 1 )+".js";
oHead.appendChild( oScript);
</script>
quantum-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-11-2010, 12:18 PM   #8
quantum-x
Confirmed User
 
quantum-x's Avatar
 
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
Quote:
Originally Posted by dready View Post
Would this do it?

<script type="text/javascript">
<!--
var rand = Math.floor(Math.random()*2)+1;
document.write('<script type="text/javascript" src="'+rand+'.js");</script>');
</script>
Also good
quantum-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-11-2010, 12:19 PM   #9
dready
Confirmed User
 
dready's Avatar
 
Industry Role:
Join Date: Oct 2002
Location: Toronto, ON
Posts: 5,247
Thanks Quantum, I'll give it a shot.
__________________
ICQ: 91139591
dready is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-11-2010, 12:24 PM   #10
BestXXXPorn
Confirmed User
 
BestXXXPorn's Avatar
 
Join Date: Jun 2009
Location: Asheville, NC
Posts: 2,277
Quote:
Originally Posted by quantum-x View Post
Bullshit. Go flip a coin 1,000,000 times and tell me if it goes out to 60/40.
It IS possible... unlikely but still possible... It also has a LOT to do with sample size :P
__________________
ICQ: 258-202-811 | Email: eric{at}bestxxxporn.com
BestXXXPorn is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-11-2010, 12:54 PM   #11
ProG
Confirmed User
 
Join Date: Apr 2009
Posts: 1,319
Quote:
Originally Posted by quantum-x View Post
Bullshit. Go flip a coin 1,000,000 times and tell me if it goes out to 60/40.
Not sure what you are saying. I know you are smart enough to know that random will never be equal. The FACT is, if you want it to be 50/50 exactly, random isn't going to work.

Also, BestXXXPorn is correct. The sample size plays a huge role. If you have 100 hits, it could very easily go 60/40.
__________________
History will be kind to me for I intend to write it.

Last edited by ProG; 06-11-2010 at 01:01 PM..
ProG is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-11-2010, 01:28 PM   #12
quantum-x
Confirmed User
 
quantum-x's Avatar
 
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
Quote:
Originally Posted by ProG View Post
Not sure what you are saying. I know you are smart enough to know that random will never be equal. The FACT is, if you want it to be 50/50 exactly, random isn't going to work.

Also, BestXXXPorn is correct. The sample size plays a huge role. If you have 100 hits, it could very easily go 60/40.
It's really simple: When a coin is flipped, it is a 50% chance of being heads or tails.
Previous flips do not influence this chance.

Therefore, it WILL average out very close to 50/50 over a large sample set - that's why I said 'flip a coin 1,000,000 times'
quantum-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-11-2010, 01:37 PM   #13
seeandsee
Check SIG!
 
seeandsee's Avatar
 
Industry Role:
Join Date: Mar 2006
Location: Europe (Skype: gojkoas)
Posts: 50,945
do true unique page load, every next time different script
__________________
BUY MY SIG - 50$/Year

Contact here
seeandsee is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-11-2010, 01:44 PM   #14
ProG
Confirmed User
 
Join Date: Apr 2009
Posts: 1,319
Quote:
Originally Posted by quantum-x View Post
It's really simple: When a coin is flipped, it is a 50% chance of being heads or tails.
Previous flips do not influence this chance.

Therefore, it WILL average out very close to 50/50 over a large sample set - that's why I said 'flip a coin 1,000,000 times'
The OP didn't ask for an average, he asked for a 50/50 split, which you can't guarantee with random. Just because you have a 50% chance of getting heads or tales does not mean you get 50% heads and 50% tales. If you made a machine to flip coins exactly the same every time (removing the random factor) you would always get the same result not 50/50.

Not to mention if he wanted to add a 3rd option, the "averages" are much worse.
__________________
History will be kind to me for I intend to write it.
ProG is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.