Java random numbers 🎲 【4 minutes】

Поделиться
HTML-код
  • Опубликовано: 11 ноя 2024

Комментарии • 269

  • @BroCodez
    @BroCodez  4 года назад +97

    import java.util.Random;
    public class Main {
    public static void main(String[] args) {

    Random random = new Random();

    int x = random.nextInt(6)+1;
    //double y = random.nextDouble();
    //boolean z = random.nextBoolean();

    System.out.println(x);

    }
    }

  • @waage_yt
    @waage_yt Год назад +41

    "Random random, equals new random. That's random."
    Wise words from our savior.

    • @shift-g3l
      @shift-g3l 3 месяца назад

      wise words from a wise man

  • @serkan7419
    @serkan7419 3 года назад +97

    random.nextInt(max - min + 1) + min ; //creates number between two numbers

    • @3omarhd878
      @3omarhd878 Год назад +2

      cant understand can someone say more details ?

    • @domenicdemski1436
      @domenicdemski1436 Год назад +23

      @@3omarhd878 say you want a random integer from 30-100. If we say int max = 100; and int min = 30; when we take the difference of those two, we will be passing 70 into the nextInt method. Note that this will only find a random number from 0-69 now, so we must add 1 inside the parentheses. Our value will now be between 0-70. Adding the min integer afterwards then allows us to generate a number from 30-100.

    • @muratcangozum2589
      @muratcangozum2589 Год назад +1

      Nice

    • @3omarhd878
      @3omarhd878 Год назад +2

      @@domenicdemski1436 thank you

    • @domenicdemski1436
      @domenicdemski1436 Год назад +2

      @@3omarhd878 gotchu

  • @aya2222
    @aya2222 3 года назад +45

    These videos are super helpful for self taught beginner!
    I'm not native English speaker but I could follow your tutorials without any problem thanks to your clear explanation.
    Thank you so much! I would like to join your class if you have one.

    • @Daniel_MZA
      @Daniel_MZA 3 года назад +4

      I´m not a native English speaker but this guy explains super! I mean I can understand English and this guy does and describes his hobby very understandable.

    • @manipurihunabopa
      @manipurihunabopa Год назад

      Everything after Bro Code teaches becomes easy.

  • @aaronjackson7942
    @aaronjackson7942 Год назад +3

    Im so happy my friend sent me to your channel, im 32 and ready to have a career change. I have been so addicted to java since starting these video's! thank you brO!

  • @emmalund7859
    @emmalund7859 2 года назад +11

    I'm so glad I found you! Straight to the point and well explained. Thank you so much!

  • @achristopoulos
    @achristopoulos 3 года назад +7

    The random double numbers have various usages for example statistics , probability etc.

  • @pavelkvasnicka6856
    @pavelkvasnicka6856 Год назад +4

    This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro

  • @xplane7879
    @xplane7879 3 года назад +6

    Me le coding:
    Random rand = new Random();
    String s = rand.nextString();
    RUclips.out.comment(s);
    RUclips: Channel recommendation improved...
    Me: Wow it worked... 😍🙏

  • @Mr.beezet
    @Mr.beezet 7 дней назад

    I love you classes bro, it really helps

  • @BLUEDAWNNN
    @BLUEDAWNNN 3 дня назад

    These videos are super helpful for self taught beginner!

  • @ShahriyarAlam1
    @ShahriyarAlam1 2 года назад +5

    I've always just used Math.random() and for a dice I normally just do double randomDouble = Math.random() * 6; and then do integer randomInt = (int)randomDouble; and then randomInt++;

    • @ejay
      @ejay Год назад +1

      Why not just cast it in the first one
      int random =(int)(Math.random()*6);

  • @DesiHabibi
    @DesiHabibi 3 года назад +2

    thx for vids !

  • @venkatasrikarkavuri2089
    @venkatasrikarkavuri2089 2 года назад +2

    I am so excited because new shrek movie was announced by the official twitter page saying Morbin' time is over and its time for shrek to play some shreksophone

    • @skyset_
      @skyset_ 9 месяцев назад

      how random of you!

  • @juanestebanparraparra6302
    @juanestebanparraparra6302 3 года назад +2

    I cant helpt it but returning to your videos whenever I wanna learn programming. Thanks Bro!

  • @Islem_ch123
    @Islem_ch123 2 месяца назад

    I'm not even good at english ethier at programming but i really like this channel it help me allot to understand java even when he speak English I'm so grateful that i found you broo thank you so much 🙏

  • @annderby6295
    @annderby6295 3 года назад +1

    Now I know how random number generation works for different data types. Thanks.

  • @filipkuchta_main
    @filipkuchta_main Год назад

    Finally answers without a need to read 10 pages manual.

  • @MAULIKPATELnamste
    @MAULIKPATELnamste 3 года назад +1

    This is GOOD !!! Variety of JAVA courses.

  • @TheDuckter
    @TheDuckter 9 месяцев назад

    "Random random, equals new random. That's random."
    I agree. Thats random.

  • @Daniel_MZA
    @Daniel_MZA 3 года назад +2

    Thanks! :) I would like to see videos about kotlin :) , But this java course I really like it :).

  • @kelleyannbart8348
    @kelleyannbart8348 Год назад +1

    Very helpful videos, thank you!!

  • @chsaireddy22
    @chsaireddy22 Год назад +1

    I wish I wanna go past and all my teachers are be like him 🥺
    Such a great explanation lot's of Gratitude to you " BRO "

  • @MAULIKPATELnamste
    @MAULIKPATELnamste 3 года назад

    This Randomness of the Universe really is helping me

  • @Barak_Mozes
    @Barak_Mozes Год назад +1

    Hey brother, you are a genius, I wish you all the best, thank you

  • @Madara2B
    @Madara2B 3 года назад +21

    decided to make it do 100, got a 69 on my 3rd roll. Worth it

  • @JuliHoffman
    @JuliHoffman 2 года назад

    I can make my own random number generator! I know this is kid stuff, but I'm so ridiculously happy right now.

  • @Simis999
    @Simis999 2 года назад

    Nobody:
    Random: Curd would book a star had the Oscars seen Additional Mouse Properties.

  • @emdorsfm1625
    @emdorsfm1625 2 года назад

    I already know alot about programing so the first like 5 vids becuz i know about Strings variables Char boolean etc. but after that it gets realy exiting i realy like java and i would love to master it and with you its so much easy thanks alot

  • @gabeishere4990
    @gabeishere4990 Год назад

    Giga Chad thumbnail in 2020? Very Chad like.

  • @TheErry98
    @TheErry98 4 года назад +5

    How can i generate a random value between -6 to 6 for example?

    • @BroCodez
      @BroCodez  4 года назад +6

      int max = 6;
      int min = -6;
      int x = random.nextInt((max+1) + max) + min;

  • @gabriellopes4361
    @gabriellopes4361 Год назад

    thank god for these channels dude... even tho im a atheist ! this video has 4 minutes but explains a lot !

  • @AliiaAbdieva
    @AliiaAbdieva Год назад

    thank you for great lesson

  • @ayhangumus9877
    @ayhangumus9877 2 года назад

    Thanks for the help before the test.

  • @melo1722
    @melo1722 Год назад +1

    int x= random.nextInt(6)+8 what happens then??

  • @honoredegg
    @honoredegg 2 года назад

    Random understood. 8th. Thank you, ma Bro Sensei!

  • @code_dynamic8211
    @code_dynamic8211 2 года назад

    Nice tutorial you got there :D

  • @meghashah5473
    @meghashah5473 2 года назад

    Superb my Random bro

  • @CodeTV-oy9sq
    @CodeTV-oy9sq Год назад +1

    thx for the knowledge!

  • @deeplife9654
    @deeplife9654 Год назад

    love for helping you beat algorithem.

  • @diegocharrycardenas457
    @diegocharrycardenas457 2 года назад

    Thanks bro great tutorial !

  • @trickysachin
    @trickysachin 2 года назад

    Your videos are informative and interesting

  • @mustafaismail9802
    @mustafaismail9802 2 года назад +1

    The Random Hypotenuse 😁😁😁
    import javax.swing.JOptionPane;
    import java.util.Random;
    public class Main {
    public static void main(String[] args) {
    Random random = new Random();
    int x = random.nextInt(100);
    System.out.println("value of x : " + Math.abs(x));
    int y = Math.abs(random.nextInt(100));
    System.out.println("value of y : " + y);
    int z = (int) Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
    System.out.println("The Hypotenuse is : " + z);
    }
    }

  • @PavneetSingh-o8z
    @PavneetSingh-o8z 23 дня назад

    very short and helpful video

  • @abdulalimmahir
    @abdulalimmahir 2 года назад

    string comment = random.nextOpinion();
    Sysout(comment, "Java is a girl, so descriptive");

  • @alexanderperez3974
    @alexanderperez3974 Месяц назад

    Best channel ever!

  • @o0QuAdSh0t0o
    @o0QuAdSh0t0o Год назад +1

    3:40 made me lol

  • @josephstaples8186
    @josephstaples8186 2 года назад

    This is the best video I have ever seen

  • @gamesandsoftwares1441
    @gamesandsoftwares1441 2 года назад

    doing my part for the algorithm AGAIN while (watching bro code){smash that like button};

  • @Savahax
    @Savahax 8 дней назад

    Love these! New binge inc

  • @stray1239
    @stray1239 2 года назад +1

    "a random comment"

  • @atheistbro6798
    @atheistbro6798 2 года назад

    one of the best class

  • @mkhyperltd
    @mkhyperltd 3 года назад +1

    Moment of silence for the poor souls who disliked our Bros Videos. All of you 15,928 ungrateful viewers as well.

  • @wallstreetbets7741
    @wallstreetbets7741 2 года назад

    thx i learnt dfro u again

  • @user-ex1zu1re1g
    @user-ex1zu1re1g 2 года назад +1

    hello, i would like to generate a random number from a specific set for example { 1,6,77,90,39 } how would i code it?

    • @PedroSilva-rn6ux
      @PedroSilva-rn6ux 2 года назад

      Hi, Did you make it?

    • @paprikar
      @paprikar 2 года назад +1

      @@PedroSilva-rn6ux just generate a random number-index, by which you get the desired number from the list

  • @NkosiHadebe-k5t
    @NkosiHadebe-k5t 2 года назад

    hello this video was super helpful, can you please tell me how you changed your background to dark mode? @Bro Code

    • @Пирамидакуба
      @Пирамидакуба 2 года назад

      There is the first video about java, so at the end of it you can find this info.

  • @rajuveerla713
    @rajuveerla713 2 года назад

    how do i take range as an input from user

  • @Bawesome1111
    @Bawesome1111 2 месяца назад

    Boolean
    Foolean
    Toolean
    Coolean
    Poolean
    Woolean

  • @BurhanTosuner
    @BurhanTosuner Год назад

    ellerinize sağlık güzel olmuş. kısa ve öz

  • @moussaei1390
    @moussaei1390 10 месяцев назад

    Guys please how to give that number a percentage for not showing up

  • @sanjaykarmakar100
    @sanjaykarmakar100 3 года назад

    1:18 Really Random!

  • @zapeeosheikh
    @zapeeosheikh 3 года назад

    @Bro Why we write. (6)+1;
    We are taking 6 values for a dice so 0 - 6 = 7 values +1 = 8
    Is it ??

    • @dildosti7769
      @dildosti7769 3 года назад +1

      Random(6); means Start from 0 to end at 6 ......
      Random(6)+1; means Start from 1 to end at 6 .......

    • @4exan599
      @4exan599 3 года назад +2

      @@dildosti7769 Random(6); means Start from 0 to end at 5*

  • @Dev-PauloEd
    @Dev-PauloEd 2 года назад

    I want to play video games, but my father won't let me do it because he thinks that it's Satan's thing

  • @afrobear2310
    @afrobear2310 Месяц назад

    Drop a pseudo-random comment guys !!!

  • @PaulLein-t9m
    @PaulLein-t9m Год назад

    Thank you.

  • @cornmoss638
    @cornmoss638 3 года назад

    RNG!
    import java.util.Random;
    /*Brandon (Insert Last Name Here)
    *March 27, 2021
    *Intro to RNG
    */
    public class RandomValues {
    public static void main(String[] args) {
    Random random = new Random();
    int x = random.nextInt(6) + 1;
    double y = random.nextDouble();
    boolean z = random.nextBoolean();

    System.out.println(x);
    System.out.println(y);
    System.out.print(z);

    }//end of main
    }//end of class

  • @cweeperyt
    @cweeperyt 4 года назад +1

    Very good Video :)

    • @BroCodez
      @BroCodez  4 года назад +1

      thanks for watching Creeper!

  • @shaysoggy1661
    @shaysoggy1661 Год назад

    Striaght to the point
    Thanks bro👍

  • @wassimelshamy4957
    @wassimelshamy4957 Год назад

    I love this guy!

  • @Wolfgirl-bi7ie
    @Wolfgirl-bi7ie 2 года назад

    blue jeans and bloody tears

  • @cesara9747
    @cesara9747 2 года назад

    hi, bro!

  • @phiphongnguyen3352
    @phiphongnguyen3352 3 года назад

    thank you very much

  • @UmeshKumar-zh8wk
    @UmeshKumar-zh8wk 3 года назад

    I have written the same code using intelliJ but error comes???

    • @zapeeosheikh
      @zapeeosheikh 3 года назад

      Make sure either you are importing the Library or not

  • @rufatalizada4006
    @rufatalizada4006 2 года назад

    Thanks bro!

  • @gregorythegrimreaperscarpa3415

    How to generate random numbers between 0 to 1?

  • @jasoncrypto4848
    @jasoncrypto4848 2 года назад

    what name this program so i can download it

  • @YuliannCastañeda
    @YuliannCastañeda 20 дней назад

    Thnaks

  • @biswajeet9826
    @biswajeet9826 5 месяцев назад

    Good Work Bruh!!
    Arigato!!

  • @Minecarthus
    @Minecarthus 3 года назад

    Thank you soooo much !!!

    • @BroCodez
      @BroCodez  3 года назад +1

      Glad it helped!

  • @freddestiny1890
    @freddestiny1890 4 года назад +1

    Hi,how can i generate a string where the first two characters are letters while the rest are numbers(example: "AX10532"). I need this to generate vehicle license plates.

    • @BroCodez
      @BroCodez  4 года назад +15

      What I would do is to create a string of all the characters you want to use:
      String myString = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
      Use the random class to create random integers
      randomNum = random.nextInt(10)
      randomLetter = random.nextInt(26)+10
      Then use the
      myString.charAt(randomNum) method to pick a random number from the string
      myString.charAt(randomLetter) method to pick a random letter from the string

    • @epikurus6913
      @epikurus6913 2 года назад +2

      @@BroCodez this is a year old but its pretty cool you reached out with such a specific answer, real bro code

    • @sairos4057
      @sairos4057 2 года назад +1

      @@BroCodez I tried to compile this but I got a error. Maybe I'm stupid.

    • @darkpal1339
      @darkpal1339 Год назад

      Thanks to your question I was able to get some good practice! Here is how I did it
      String myString = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

      Random randomNum = new Random();

      String newString =
      String.valueOf(myString.charAt(randomNum.nextInt(10)+26))
      + String.valueOf(myString.charAt(randomNum.nextInt(10)+26))
      + String.valueOf(myString.charAt(randomNum.nextInt(10)))
      + String.valueOf(myString.charAt(randomNum.nextInt(10)))
      + String.valueOf(myString.charAt(randomNum.nextInt(10)))
      + String.valueOf(myString.charAt(randomNum.nextInt(10)))
      + String.valueOf(myString.charAt(randomNum.nextInt(10)));

      //"String.valueOf" converts char to String

      System.out.println(newString);

  • @itlogskina
    @itlogskina 3 года назад

    Thank you

  • @emmanueljr
    @emmanueljr 2 года назад

    Can anyone explain how random.nextInt(6)+1 gives us a range of 1-6? I thought we’d now be getting a range of 0-7

    • @bryanZ17
      @bryanZ17 2 года назад

      I'm not 100 percent sure either buy maybe since the starting value is always 0, then by adding +1, it changes the starting value to 1? 🤔

    • @emmanueljr
      @emmanueljr 2 года назад

      @@bryanZ17 Yup, makes sense. Thank you

  • @zapeeosheikh
    @zapeeosheikh 3 года назад

    What is the purpose of
    Scanner.close();

    • @We-tz8ko
      @We-tz8ko 3 года назад

      to close the scanner class imported from java

  • @mindreader860
    @mindreader860 3 года назад

    Excellent Bro ☺♥

  • @garvtech9721
    @garvtech9721 2 года назад

    thank u soo much u help me lot

  • @matinmonshizadeh
    @matinmonshizadeh 3 года назад

    Thank you bro

  • @armanali9594
    @armanali9594 3 года назад

    this code is very useful for me

  • @mibahealthandnutrition4569
    @mibahealthandnutrition4569 3 года назад

    If you increase the min value this code give errors.
    import java.util.Random;
    public class RandomNumber2 {
    // If the min > 1 some things is wrong after many turns comes over max limit
    public static void main(String[] args) {
    int error = 0;
    int min = 2;
    int max = 6;
    Random random = new Random();
    for (int x = 1; x < 1000; x++) {
    int randomNumber = random.nextInt(max) + min;// Limited the range
    // double y = random.nextDouble();
    // boolean z = random.nextBoolean();
    System.out.println(randomNumber);
    if (randomNumber > max) {
    System.out.println("ERROR over limit");
    error++;
    }
    }
    System.out.println(error + " ERRORS");
    }
    }

  • @yassinebouziane7470
    @yassinebouziane7470 3 года назад

    You are the best! I am italian if you want i'll take you pizza hahah.

  • @vidhigill5301
    @vidhigill5301 2 года назад

    nice one bro

  • @omersond4891
    @omersond4891 3 года назад

    Hello

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 года назад

    Thanks

  • @brawkju3876
    @brawkju3876 3 года назад

    Nice Bro ;)

  • @bartomiejsniadach5795
    @bartomiejsniadach5795 2 года назад

    another great one

  • @ibrahimylmaz8378
    @ibrahimylmaz8378 2 года назад

    you are amazing!

  • @MC_Transport
    @MC_Transport 4 месяца назад

    4:20 A random comment

  • @trypwyre9024
    @trypwyre9024 3 года назад

    Randomizers, eh?

  • @مجهول-ن5ع7ن
    @مجهول-ن5ع7ن 11 месяцев назад

    how i can do random letters ?, like random password

  • @JaronDCosta
    @JaronDCosta 3 года назад

    what if randomness was random this random thought makes no sense and is therefor a random comment. XD

  • @PoorwayTraning
    @PoorwayTraning Год назад

    thanks