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

# Thread: Random Lotto Number Generator

1. ## Random Lotto Number Generator

I've sort of got stuck with my random lotto number generator and need a helpful nudge. If anyone has got some helpful insights to get my lotto number generator to work, that would be awesome.

Code:
```<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<title>Lottery Number Generator</title>
<script language="JavaScript" type="text/javascript">

function Lottery() {
this.balls = new Array();
this.freshSet = freshSet;
this.selectOneNumber = selectOneNumber;
}

function freshSet(maxNumber) {
maxNumber=parseInt(maxNumber);
if( isNaN(maxNumber) || maxNumber<0 ) maxNumber=0;
// create new set of balls numbered from 1 to maxNumber inclusive

for (var k=0; k<maxNumber; k++) this.balls[k] = k+1;
}

function selectOneNumber() {
if( this.balls.length<1 ) return -1;
var i = Math.random()*this.balls.length;
i = Math.floor(i);
return this.balls.splice(i,1);
}

function Lotto()
{

var newballs = Lottery

return false;

}
// THIS SECTION OF CODE (ABOVE) MUST BE USED WITHOUT MODIFICATION

//]]>
</script>

<body bgcolor="#FFFFFF">
<h2>Lottery Number Generator</h2>

<form method="get" action="" onsubmit="return Lotto();" name="lotto" id="numbers">
<table border="0">
<tr>

<td><input type="text" size="2" name="num" /></td>
<td><input type="text" size="2" name="num" /></td>
<td><input type="text" size="2" name="num" /></td>
<td><input type="text" size="2" name="num" /></td>
<td><input type="text" size="2" name="num" /></td>
<td><input type="text" size="2" name="num" /></td>
</tr>

<td><input type="submit" value="Roll Those Numbers" /></td>
</tr>
</table>
</form>
</body>
</html>```

2. Is that the original state of the template you were handed, or have you added to it?

If all you're doing is displaying the numbers, then there's no real need even to store them.

Code:
```<script  type="text/javascript">

function Lottery( count, max )
{

this.balls = new Array();
this.freshSet = freshSet;

this.freshSet( count, max );
}

function freshSet( ballCount, maxNumber )
{
var ballSet = [];

for (var k=0; k<maxNumber; k++ )
ballSet[k] = k+1;

for( var i = 0; i < ballCount; i++ )
this.balls.push( ballSet.splice( Math.floor( Math.random() * ballSet.length ), 1 )[0] );

}

function Lotto()
{
var newballs = new Lottery( 6,49 );

return false;
}```

3. Yeah - that would be very inefficient. /face palms self

#### Posting Permissions

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