I'm trying to make a program where Math.random() generated a list of random numbers as ints between the range of 3 and 9. I keep getting long decimals and numbers such as 0, or 1. I'm not sure if it's the output() or is my process right? Or is it something simple like typecasting?
Here's the output i'm getting with this code:
--------------------Configuration: <Default>--------------------
5.855672310088313
5.0287286763569625
5.1257975957882485
3.2283987551436173
0.8364642553235297
3.5005965809506696
3.284959203422762
1.3896135045374878
2.8493705949526733
0.7431149270852646
Process completed.
Im trying to get something more along the lines of a list of 10 random numbers between 3 and 9.
import static java.lang.System.*;
import java.util.*;
public class Java1605{
public static void main(String[] args){
new Problem();
}}
class Problem
{
int low;
int high;
int range;
public Problem()
{
low = 3;
high = 9;
range = (int)((Math.random() * (high - low )) + low);
output();
}
public void output()
{
out.println(Math.random()* range);
out.println(Math.random()* range);
out.println(Math.random()* range);
out.println(Math.random()* range);
out.println(Math.random()* range);
out.println(Math.random()* range);
out.println(Math.random()* range);
out.println(Math.random()* range);
out.println(Math.random()* range);
out.println(Math.random()* range);
}
}