0
Generating random number in JAVA
How can i generate randome number in java in output file, by using random.rand?
8 Respuestas
+ 11
JazzyB
in above comment , loop will run infinite times , until time-limit exceeds
//U can do like this for running desired number of times:
int a =10; //for running 10 times
while(a-- > 0){
//statement(s);
}
//btw U can use any loop , recursion , stream etc .
+ 10
//using Random Class
● import Random class
//import java.util.Random;
●create an object of that class & generate a random number from 1 to 99
/*
Random R1 = new Random();
number1 = 1 + R1.nextInt(99);
//1 is added because R1.nextInt(99) generates random number from 0 to 98
number 2= 1 + R1.nextInt(99);
//here is sample code :
import java.util.Random;
public class Program{
public static void main(String[] args) {
while(true){
int number = 1 + (new Random()).nextInt(99);
//generating number from 1 to 99 (both included)
System.out.println(number);
}
}
}
+ 2
do i have to use while loop?
+ 1
between 1 to 99
+ 1
like genuinly i have to generate points. x,y to an ouput file, can you please ealborate the algo?
+ 1
and thank you so much for reply
+ 1
thanks gaurav,
0
appericiated Gaurav but how many time will this loop rotate?