8.582
Bearbeitungen
Jneug (Diskussion | Beiträge) |
Jneug (Diskussion | Beiträge) |
||
| Zeile 363: | Zeile 363: | ||
! Beispiel | ! Beispiel | ||
|- | |- | ||
| Zufällige ganze Zahl von <code>0</code> bis <code>max-1</code> | | Zufällige ganze Zahl von <code>0</code> bis <code>max-1</code> erzeugen. | ||
| {{nowrap|'''int nextInt(int max)'''}} | | {{nowrap|'''int nextInt(int max)'''}} | ||
| <syntaxhighlight lang="java"> | | <syntaxhighlight lang="java"> | ||
| Zeile 370: | Zeile 370: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |- | ||
| Zufälligen Wahrheitswert | | Zufälligen Wahrheitswert erzeugen. | ||
| {{nowrap|'''boolean | | {{nowrap|'''boolean nextBoolean()'''}} | ||
| <syntaxhighlight lang="java"> | | <syntaxhighlight lang="java"> | ||
Random rand = new Random(); | Random rand = new Random(); | ||
boolean zufall = rand. | boolean zufall = rand.nextBoolean(); | ||
</syntaxhighlight> | |||
|- | |||
| Zufällige Zahl zwischen 0 und 1 erzeugen, wobei 1 niemals erzeugt wird (exklusive). | |||
| {{nowrap|'''double nextDouble()'''}} | |||
| <syntaxhighlight lang="java"> | |||
Random rand = new Random(); | |||
double zufall = rand.nextDouble(); | |||
</syntaxhighlight> | </syntaxhighlight> | ||
|} | |} | ||