question:
suppose give a function Randomnized(1,N), it can generate from 1 to N random Integer number, pls use this function to accomplish a most effective program, it can generate 6 unduplicate nubmers.
answer:
public
class
RamdomNumber {
public
static
void
main(String[] args) {
int
numbers[]=
new
int
[50];
//add values to numbers array
for
(
int
i=0;i<50 ;i++ )
{
numbers[i] = i+1;
}
int
[] luckyNumbers =
new
int
[20];
int
i = 50;
for
(
int
j = 0; j < 20; j++)
{
int
index = (
int
)(Math.random()*(i-1));
System.
out
.println(index);
System.
out
.println(
"*************"
);
luckyNumbers[j] = numbers[index];
numbers[index] = numbers[numbers.
length
-j-1];
i--;
}
//output the values
for
(
int
t = 0; t < 20 ; t++)
{
System.
out
.println(luckyNumbers [t]);
}
}
}