|
Per Java Zufallszahl > 0.0 und < 1.0 generieren
public class Test{
public static void main (String args[]) {
double zufall = Math.random(); // Zufallszahl von 0.00000... bis 0.9999...
System.out.println(zufall);
}
}
Ganzzahlige Zufallszahl zw. 0 und 5
public class Test{
public static void main (String args[]) {
int zufall = (int) (Math.random()*6); // Zufallszahl von 0 bis 5
System.out.println(zufall);
}
}
Ganzzahlige Zufallszahl zwischen 1 und 6
public class Test{
public static void main (String args[]) {
int zufall = 1 + (int)(Math.random() * 6);
System.out.println(zufall);
}
}
|