Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Randomizing

  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Randomizing

    Hello, I'm having issues trying to make an alphabetic randomizer... specifically, it needs to only randomize the order of 2 letters each time the page is reloaded.

    Here is the code I currently have in place, but when I try and load it in my browser I get a blank screen.

    Code:
    <script type="text/javascript">
    //<![CDATA[
    <!--
    Long.toHexString(Double.doubleToLongBits(Math.random()));
    
    //
    
    //-->
    //]]>
    </script>
    This is the code I'm using for it, but it won't show up at all! I hijacked the code from here: http://mynotes.wordpress.com/2009/07...random-string/

    Thank you in advance! Would it help if I posted my whole HTML file? It's not very big but it might help.

  • #2
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok now I've decided to use a modified version of vwphillips's code from http://www.codingforums.com/archive/...p/t-89056.html

    Code:
    <html><head><title>Random Order</title>
    
    <script language="JavaScript" type="text/javascript">
    /*<![CDATA[*/
    
    
    var formAry=['Z','Y']
    var scaleAry=['Y','Z']
    
    var TO;
    
    function Notes(id,spd){
    var table=document.getElementById(id);
    var cells=table.getElementsByTagName('TD');
    table.style.fontSize='20px';
    clearTimeout(TO);
    NotesDo(cells,spd);
    }
    
    function NotesDo(cells,spd){
    cells[2].innerHTML=formAry[Math.floor(Math.random()*formAry.length)];
    cells[3].innerHTML=scaleAry[Math.floor(Math.random()*scaleAry.length)];
    TO=setTimeout(function(){ NotesDo(cells,spd); },spd);
    }
    
    /*]]>*/
    </script></head>
    
    <body>
    <table id="notes" cellpadding="0" cellspacing="0" border="1" >
    <tr>
    <td width=100 align=center >First Test</td>
    <td width=100 align=center >Second Test</td>
    </tr>
    <tr >
    <td width=100 align=center >Z, Y</td>
    <td width=100 align=center >Y, Z</td>
    </tr>
    </table>
    <input type="button" value="Randomize" onclick="Notes('notes',10000);" />
    </body>
    
    </html>
    Is there a way to make it so that the same characters do not show up in both cells? I tried removing one of the cells, but every time I did anything to modify the B cells I broke the randomizer completely.

    Tips?

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    [QUOTE=Spency;1294201]Hello, I'm having issues trying to make an alphabetic randomizer... specifically, it needs to only randomize the order of 2 letters each time the page is reloaded.

    Here is the code I currently have in place, but when I try and load it in my browser I get a blank screen.

    Code:
    <script type="text/javascript">
    //<![CDATA[
    <!--
    Long.toHexString(Double.doubleToLongBits(Math.random()));
    
    //
    
    //-->
    //]]>
    </script>
    That code is JAVA, not Javascript. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia! Ask a mod to move this thread to the right forum.

    If all you want to do is randomize the order of two letters on page load, then


    Code:
    <script type = "text/javascript">
    
    var twoletters = "XY"
    var now = new Date().getSeconds();  // returns 0-59
    if (now%2 == 0) {  // even number
    twoletters = "YX";
    }
    alert (twoletters);
    
    </script>


    Quizmaster: The small primates called lemurs are native to which large island off the coast of Africa?
    Contestant: Argentina.
    Last edited by Philip M; 11-23-2012 at 01:13 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •