waltbaby315
asked on
How do you get this program to generate different numbers out of the output
How do you get this program to generate different numbers out of the output ?
public class First
{
public static void main(String[] args) {
int n = (int)Math.floor(Math.rando m()*100000 +1);
int digit;
System.out.println(" Number generated 235:235 ");
System.out.println(" Sum of digits =26 ");
}
}
public class First
{
public static void main(String[] args) {
int n = (int)Math.floor(Math.rando
int digit;
System.out.println(" Number generated 235:235 ");
System.out.println(" Sum of digits =26 ");
}
}
I'm afraid that I don't know anything about AS400 programming, but do recall a Randomize () command in some other language (BASIC?). It would set a new "seed" in the randomizer so you'd get a different set of numbers. The seed was put in the parentheses. If you used the system timer to provide the seed for that function, you could have a pretty good approximation of randomness.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Your class always generates different numbers
I ran several times and they do not repeat
at least inmy environement:
First run:
Second run:
Third run:
I ran several times and they do not repeat
at least inmy environement:
public class First
{
public static void main(String[] args) {
for(int j=0; j<10; j++){
int n = (int)Math.floor(Math.random()*100000+1);
System.out.println(n);
}
int digit;
System.out.println(" Number generated 235:235 ");
System.out.println(" Sum of digits =26 ");
}
}
First run:
51323
21948
83732
56684
50138
67735
86410
81695
14470
1583
Second run:
44085
53945
46097
87346
96627
61915
53862
70963
50484
6035
Third run:
29810
34882
49513
33293
52201
20012
64157
53449
31641
74458
//for example to print 100 numbers
public class First
{
public static void main(String a[])
{
Random random = new Random():
while(count < 100)
{
System.out.println(random. nextInt()) ;
count++;
}
}
}
public class First
{
public static void main(String a[])
{
Random random = new Random():
while(count < 100)
{
System.out.println(random.
count++;
}
}
}