public int getRnd(int begin, int end) { int k = Math.round((float)begin + (float)Math.random() * (float)(end - begin)); return k;//k在begin和end之间 }
import java.util.Random; public class rand { public static void main(String[] args) { Random rand1=new Random(); System.out.println(rand1.nextInt()); } }
(int)【或者其他】math.radom()
import java.util.Random; public class rand { public static void main(String[] args) { Random rand1=new Random(); for(int i=0;i<10;i++) { System.out.println(rand1.nextInt(100)); } } } 就产生0-100的一个任意数
int random = (int)(java.lang.math.random()*10000); 产生最大9999的随机数
{
int k = Math.round((float)begin + (float)Math.random() * (float)(end - begin));
return k;//k在begin和end之间
}
public class rand {
public static void main(String[] args) {
Random rand1=new Random();
System.out.println(rand1.nextInt());
}
}
public class rand {
public static void main(String[] args) {
Random rand1=new Random();
for(int i=0;i<10;i++)
{
System.out.println(rand1.nextInt(100));
}
}
}
就产生0-100的一个任意数
产生最大9999的随机数