Javascript to alternate between two sources

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dready
    Confirmed User
    • Oct 2002
    • 5247

    #1

    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
  • BestXXXPorn
    Confirmed User
    • Jun 2009
    • 2277

    #2
    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

    Comment

    • ProG
      Confirmed User
      • Apr 2009
      • 1319

      #3
      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.

      Comment

      • AIbenjamink
        Confirmed User
        • Jan 2009
        • 420

        #4
        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

        Comment

        • quantum-x
          Confirmed User
          • Feb 2002
          • 6863

          #5
          Originally posted by ProG
          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.
          PrettyInCash.com - BoozedGFs.com - TeenGFs.com - JizzGFs.com- MilfUploads.com -

          Comment

          • dready
            Confirmed User
            • Oct 2002
            • 5247

            #6
            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

            Comment

            • quantum-x
              Confirmed User
              • Feb 2002
              • 6863

              #7
              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>
              PrettyInCash.com - BoozedGFs.com - TeenGFs.com - JizzGFs.com- MilfUploads.com -

              Comment

              • quantum-x
                Confirmed User
                • Feb 2002
                • 6863

                #8
                Originally posted by dready
                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
                PrettyInCash.com - BoozedGFs.com - TeenGFs.com - JizzGFs.com- MilfUploads.com -

                Comment

                • dready
                  Confirmed User
                  • Oct 2002
                  • 5247

                  #9
                  Thanks Quantum, I'll give it a shot.
                  ICQ: 91139591

                  Comment

                  • BestXXXPorn
                    Confirmed User
                    • Jun 2009
                    • 2277

                    #10
                    Originally posted by quantum-x
                    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

                    Comment

                    • ProG
                      Confirmed User
                      • Apr 2009
                      • 1319

                      #11
                      Originally posted by quantum-x
                      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.
                      Last edited by ProG; 06-11-2010, 12:01 PM.
                      History will be kind to me for I intend to write it.

                      Comment

                      • quantum-x
                        Confirmed User
                        • Feb 2002
                        • 6863

                        #12
                        Originally posted by ProG
                        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'
                        PrettyInCash.com - BoozedGFs.com - TeenGFs.com - JizzGFs.com- MilfUploads.com -

                        Comment

                        • seeandsee
                          Check SIG!
                          • Mar 2006
                          • 50945

                          #13
                          do true unique page load, every next time different script
                          BUY MY SIG - 50$/Year

                          Contact here

                          Comment

                          • ProG
                            Confirmed User
                            • Apr 2009
                            • 1319

                            #14
                            Originally posted by quantum-x
                            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.

                            Comment

                            Working...