PDA

View Full Version : Need help for Lottery picker script



Jy2m
04-22-2018, 11:53 AM
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.

jscheuer1
04-22-2018, 02:12 PM
Could you be clearer about that please? There is no Y. And X never represents just one number.

Jy2m
04-23-2018, 03:40 PM
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.

jscheuer1
04-23-2018, 03:58 PM
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.

jscheuer1
04-23-2018, 04:41 PM
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).


<!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.

jscheuer1
04-23-2018, 05:34 PM
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).


<!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.

Jy2m
04-24-2018, 12:11 PM
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.6289

jscheuer1
04-24-2018, 02:57 PM
<!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>