Lottery draw

Mohan0704 0 Tallied Votes 160 Views Share

Random numbers from 1-50 are drawn and displayed in a alert dialog box.

var i, rand, temp, str;
var nums = new Array(50)
for (i = 1; i < 51; i++) nums[i] = i;
for (i = 1; i < 51; i++)
{
rand = Math.ceil(Math.random() * 50);
temp = nums[i];
nums[i] = nums[rand];
nums[rand] = temp;
}
str = "Your six lucky numbers are:\n\n";
for (i = 1; i < 7; i++)
{
str +=nums[i];
if (i != 6)
{
str += " - "
}
}
alert (str);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.