Results 1 to 8 of 8

Thread: Need help for Lottery picker script

  1. #1
    Join Date
    Apr 2018
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Need help for Lottery picker script

    Hi,

    About the script "Lottery Picker" anyone to tell me what I must change to obtain next number Y always superior to X + 1 (Y > X + 1)

    Thanks.

    Jy2m.
    Last edited by jscheuer1; 04-23-2018 at 03:59 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Could you be clearer about that please? There is no Y. And X never represents just one number.
    Last edited by jscheuer1; 04-22-2018 at 02:43 PM. Reason: add info
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Apr 2018
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Quote Originally Posted by jscheuer1 View Post
    Could you be clearer about that please? There is no Y. And X never represents just one number.
    Of course it isn't X an Y but, to explain me, imagine a draw like that :

    7 15 21 22 43 55

    the problem is that the fourth result (22) is equal to the third (21) +1 and I don't want it
    I want that each number be at least equal to the preedent + 2.
    In my example the fourth result would be for instance 23 or more.
    So the question is : how modify he script to obtain this result?
    Thanks.
    Jy2m.
    Last edited by jscheuer1; 04-23-2018 at 03:54 PM.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Since this is essentially the current version of:

    http://www.dynamicdrive.com/dynamicindex12/lottery.htm

    Please stop attaching it to your posts.

    That said, I'm pretty sure this can be done. I'll let you know.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    OK, this seems to do the trick (NOTE: do not copy code from a message the forum might send you, it could be corrupted, rather log on and copy from the post).

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style type="text/css">
    .a1{
    position:relative;
    font-family:Verdana;
    font-size:20px;
    color:#888888;
    }
    </style>
    
    <script>
    
    /*****************************************
    * Lottery Picker (By Kurt at kurt.grigg@virgin.net)
    * Featured on/available at http://www.dynamicdrive.com/
    * Modified by DynamicDrive.com for below config options
    * This notice must stay intact for use.
    *****************************************/
    
    var totalnumbers=10 //input total numbers to generate
    var lowerbound=1   //input lower bound for each random number
    var upperbound=70  //input upper bound for each random number
    
    function lotto(){
    var B=' ', LottoNumbers=[], RandomNumber, i, j, X, OutPut;	
     for (i = 1; i <= totalnumbers; i++)
     {
     RandomNumber = Math.round(lowerbound+Math.random()*(upperbound-lowerbound));
      for (j = 1; j <= totalnumbers; j)
      {
      if (RandomNumber == LottoNumbers[j])
        {
         RandomNumber=Math.round(lowerbound+Math.random()*(upperbound-lowerbound));
         j=0;
        }
      j++;
      }
     LottoNumbers[i]=RandomNumber;
     }
    LottoNumbers=LottoNumbers.toString();
    X=LottoNumbers.split(',');
     for (i=0; i < X.length; i++)
     {
     X[i]=X[i]+' ';
     if (X[i].length==2) 
     X[i]='0'+X[i];
     } 
    X=X.sort();
     for (i=0; i < X.length; i++)
     {
     if(i && X[i - 1] == X[i] - 1) {X[i] = +X[i] + 1 + ' ';if (X[i].length==2)X[i]='0'+X[i];}
     if(i && X[i - 1] == X[i]) {X[i] = +X[i] + 2 + ' ';if (X[i].length==2)X[i]='0'+X[i];}
     OutPut=B+=X[i];
     }
    
    document.getElementById("layer1").innerHTML=OutPut;
    
      lotto.T=setTimeout(lotto,20);
    //window.status=OutPut;
    }
    function StOp(){
    setTimeout(function(){clearTimeout(lotto.T);},1000);
    }
    </script>
    </head>
    <body>
    <table border='0' width=350 height=50>
    <tr valign='middle'>
    <td align='center'>
    <form name=form>
    <input type=button value='Lottery Number Picker' onClick="lotto();StOp()">
    </form>
    <span id=layer1 class=a1>Result</span>
    </td>
    </tr>
    </table>
    </body>
    </html>
    Any questions or problems, just let me know.

    It just occurred to me that if the second to last number is the upperbound - 1, this would force the last number to be upperbound + 1. It would be tough to get that out of the code. But you could always just make upperbound 1 less than the actual upper limit. Then it would be fine, except that number (the true upperbound) would then be less likely to occur.
    Last edited by jscheuer1; 04-23-2018 at 04:54 PM. Reason: add info, later minor code improvement
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Here's an even better solution (NOTE: do not copy code from a message the forum might send you, it could be corrupted, rather log on and copy from the post).

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style type="text/css">
    .a1{
    position:relative;
    font-family:Verdana;
    font-size:20px;
    color:#888888;
    }
    </style>
    
    <script>
    'use strict';
    if(![].indexOf){ // for IE 8 and less
    	Array.prototype.indexOf = function(v, i){
    		var l = this.length;
    		if(typeof i === 'number'){if(i < 0){i = l + i;}} else {i = 0;}
    		--i;
    		while(++i < l){if(v === this[i]){return i;}}
    		return -1;
    	}
    }
    
    /*****************************************
    * Lottery Picker (By Kurt at kurt.grigg@virgin.net)
    * Featured on/available at http://www.dynamicdrive.com/
    * Modified by DynamicDrive.com for below config options
    * This notice must stay intact for use.
    *****************************************/
    
    function lotto(){
    	var totalnumbers = 10 //input total numbers to generate
    	var lowerbound = 1   //input lower bound for each random number
    	var upperbound = 70  //input upper bound for each random number
    
    	var LottoNumbers = [], RandomNumber, i = totalnumbers,
    	io = function(n){return LottoNumbers.indexOf(n) > -1;},
    	getRand = function(min, max){return Math.floor(Math.random() * (max - min + 1)) + min;};
    	while (--i > -1){
    		RandomNumber = getRand(lowerbound, upperbound);
    		while (io(RandomNumber) || io(RandomNumber - 1) || io(RandomNumber + 1)){
    			RandomNumber = getRand(lowerbound, upperbound);
    		}
    		LottoNumbers[i] = RandomNumber;
    	}
    	while (++i < totalnumbers){
    		LottoNumbers[i] = LottoNumbers[i] < 10? '0' + LottoNumbers[i] : LottoNumbers[i] + '';
    	}
    	document.getElementById("layer1").innerHTML = LottoNumbers.sort().join(' ');
    	lotto.T = setTimeout(lotto, 20);
    }
    function StOp(){
    	setTimeout(function(){clearTimeout(lotto.T);}, 1000);
    }
    </script>
    </head>
    <body>
    <table border="0" width="350" height="100">
    <tr>
    <td align="center" valign="middle" height="100%">
    <form name="form">
    <input type="button" value="Lottery Number Picker" onclick="lotto();StOp();">
    </form><br>
    <div id="layer1" class="a1">Result</div>
    </td>
    </tr>
    </table>
    </body>
    </html>
    This version does not have the problem of going out of range.
    Last edited by jscheuer1; 04-25-2018 at 02:36 AM. Reason: code improvements
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Apr 2018
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Bravo, it works very well

    Bravo, it works very well. Thank you very much. May I ask you one last question? I was used to the javascript version (attached) with which the digits from 1 to 9 were written 1 2 3 4 5 6 8 9 and not 01 02 03 04 05 06 07 08 09. Is this possible with your modified version?
    Thanks.
    Jy2m.Javascript_version.txt

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style type="text/css">
    .a1{
    position:relative;
    font-family:Verdana;
    font-size:20px;
    color:#888888;
    }
    </style>
    
    <script>
    'use strict';
    if(![].indexOf){ // for IE 8 and less
    	Array.prototype.indexOf = function(v, i){
    		var l = this.length;
    		if(typeof i === 'number'){if(i < 0){i = l + i;}} else {i = 0;}
    		--i;
    		while(++i < l){if(v === this[i]){return i;}}
    		return -1;
    	}
    }
    
    /*****************************************
    * Lottery Picker (By Kurt at kurt.grigg@virgin.net)
    * Featured on/available at http://www.dynamicdrive.com/
    * Modified by DynamicDrive.com for below config options
    * This notice must stay intact for use.
    *****************************************/
    
    function lotto(){
    	var totalnumbers = 10 //input total numbers to generate
    	var lowerbound = 1   //input lower bound for each random number
    	var upperbound = 70  //input upper bound for each random number
    
    	var LottoNumbers = [], RandomNumber, i = totalnumbers,
    	io = function(n){return LottoNumbers.indexOf(n) > -1;},
    	getRand = function(min, max){return Math.floor(Math.random() * (max - min + 1)) + min;},
    	numeric = function(a, b){return a - b;};
    	while (--i > -1){
    		RandomNumber = getRand(lowerbound, upperbound);
    		while (io(RandomNumber) || io(RandomNumber - 1) || io(RandomNumber + 1)){
    			RandomNumber = getRand(lowerbound, upperbound);
    		}
    		LottoNumbers[i] = RandomNumber;
    	}
    	document.getElementById("layer1").innerHTML = LottoNumbers.sort(numeric).join(' ');
    	lotto.T = setTimeout(lotto, 20);
    }
    function StOp(){
    	setTimeout(function(){clearTimeout(lotto.T);}, 1000);
    }
    </script>
    </head>
    <body>
    <table border="0" width="350" height="100">
    <tr>
    <td align="center" valign="middle" height="100%">
    <form name="form">
    <input type="button" value="Lottery Number Picker" onclick="lotto();StOp();">
    </form><br>
    <div id="layer1" class="a1">Result</div>
    </td>
    </tr>
    </table>
    </body>
    </html>
    Last edited by jscheuer1; 04-25-2018 at 02:35 AM. Reason: code improvement
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Replies: 2
    Last Post: 06-14-2015, 01:14 PM
  2. Lottery Picker
    By Sombra6 in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 02-03-2013, 05:40 PM
  3. About Lottery Picker
    By pangetkah002 in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 12-03-2008, 02:34 PM
  4. Lottery Picker Script-Justification
    By kgilbert in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 12-28-2006, 11:44 PM
  5. California Super Lottery Plus Number Picker
    By cucunusa in forum Submit a DHTML or CSS code
    Replies: 0
    Last Post: 09-10-2006, 07:58 PM

Bookmarks

Posting Permissions

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