Java | How to get random numbers (int/double/long/etc) 2020

preview_player
Показать описание
In this tutorial I'll show you one way to get random numbers. So random integer, double, long etc. I hope you enjoy this tutorial about random numbers/how to make a random number generator and if you have any questions just leave them in the comments and I'll try to answere them :)

Text tutorial. (how to do it for strings is further down)

2: *Define a variable* to which you want to assign your random number to.
In the tutorial I showed it with an Integer but you can use doubles longs basically any data type that uses numbers.

3. Type this code. *'Your Variable' = new Random().nextInt('Range');*
You can replace the Int in next in if you used something other than an integer. So if you used double for example you would type "nextDouble"
Everything that I put under quotation ( ' ) needs to be replaced by you (without the quotation marks)

Now you are done.

*Code example: *
package main;

public class RNDM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Double rdm;

rdm = new Random().nextDouble();

}

}

*How to do it for Strings using the "UUID method"*

2. Define a String.

3. Enter this code. 'Your Variable' = UUID.randomUUID().toString();

*Code example: *


public class JavaRandomStringExample {

public static void main(String[] args) {

for(int i=0; i"less than"10; i++){ //Youtube doesn't allow angled brackets

String strRandomString = UUID.randomUUID().toString();

}

}

}

I hope this helps :)
If you got any questions just leave them in the comments

Music:
Track 1: dj quads - it’s near
Рекомендации по теме
Комментарии
Автор

I created a discord so I can help you out better in case this video didn't help (mainly because it usually takes longer for me to see your comments). So if you still need help I'd be glad to help you out over there

Reewen
Автор

im trying to make trivia with randoms Questions by using math random from 1 to 10 but im trying to make them unrepeated it doesnt work at all... plz i will very appreciate if you would help me

superman-btso
Автор

how to use this inside another programm ? how to link that in the new prg ?

s_ms
visit shbcf.ru