David Harrison
05-18-2003, 09:26 AM
I was asked by my Grandad to make a program that chooses lottery numbers. Easy I thought, no it wasn't.
The part of the script that gets the numbers is shown below and as you can see it has many loops in it. Mostly there for trying to make sure that none of the numbers are the same, however sometimes some numbers are the same which means that I've done something wrong, can anyone tell me what it is please.
while(true){escape="yes";o=0;
for(n=0;n<6;n++){nums[n]=Math.round((Math.random()*48)+1);
for(o=n-1;o>=0;o--){if(nums[n]==nums[o]){nums[n]=Math.round((Math.random()*48)+1);}}
if(nums[n]<10){nums[n]="0"+nums[n];}}
while(escape=="yes" && o<5){o++;while(escape=="yes" && n<6){n=o+1;n++;if(nums[o]==nums[n]){escape="no";}}}
if(escape=="yes"){break;}}
The part of the script that gets the numbers is shown below and as you can see it has many loops in it. Mostly there for trying to make sure that none of the numbers are the same, however sometimes some numbers are the same which means that I've done something wrong, can anyone tell me what it is please.
while(true){escape="yes";o=0;
for(n=0;n<6;n++){nums[n]=Math.round((Math.random()*48)+1);
for(o=n-1;o>=0;o--){if(nums[n]==nums[o]){nums[n]=Math.round((Math.random()*48)+1);}}
if(nums[n]<10){nums[n]="0"+nums[n];}}
while(escape=="yes" && o<5){o++;while(escape=="yes" && n<6){n=o+1;n++;if(nums[o]==nums[n]){escape="no";}}}
if(escape=="yes"){break;}}