Random number generator in JavaScript 🎲【4 minutes】

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ก.ย. 2024
  • #Javascript #random #number #generator
    let x;
    let y;
    let z;
    document.getElementById("rollButton").onclick = function(){
    x = Math.floor(Math.random() * 6) + 1;
    y = Math.floor(Math.random() * 6) + 1;
    z = Math.floor(Math.random() * 6) + 1;
    document.getElementById("xlabel").innerHTML = x;
    document.getElementById("ylabel").innerHTML = y;
    document.getElementById("zlabel").innerHTML = z;
    }

ความคิดเห็น • 77

  • @BroCodez
    @BroCodez  2 ปีที่แล้ว +43

    let x;
    let y;
    let z;
    document.getElementById("rollButton").onclick = function(){
    x = Math.floor(Math.random() * 6) + 1;
    y = Math.floor(Math.random() * 6) + 1;
    z = Math.floor(Math.random() * 6) + 1;
    document.getElementById("xlabel").innerHTML = x;
    document.getElementById("ylabel").innerHTML = y;
    document.getElementById("zlabel").innerHTML = z;
    }



    Document



    roll

    • @scpf2360
      @scpf2360 2 ปีที่แล้ว

      Thx

    • @mraloush8959
      @mraloush8959 ปีที่แล้ว

      ily

    • @joyceasante8292
      @joyceasante8292 ปีที่แล้ว

      Practicing...

      Document

      roll
      ***********************************
      //Generating a random decimal number between 0 and 1
      /*
      let x = Math.random();
      console.log(x);
      */
      //Generating a random number between 1 and 6(with a dice) but 0 and 5 technically
      /*
      let x = Math.random() * 6;
      console.log(x);
      */
      //Generating a random number between 0 an 5
      /*
      let x = Math.floor(Math.random() * 6);
      console.log(x);
      */
      //Generating a random number between 1 and 6
      /*
      let x = Math.floor(Math.random() * 6) + 1;
      console.log(x);
      */

  • @buwithegoat
    @buwithegoat ปีที่แล้ว +8

    At 0:26 to be precise Math.random() will output a value of >= 0 and less than (not equal) to 1

  • @alexdin1565
    @alexdin1565 2 ปีที่แล้ว +16

    can you make a complete playlist like this on react js, please this is my first day on your channel and you are really life saver

  • @jerogentil5287
    @jerogentil5287 2 ปีที่แล้ว +7

    > discusses javascript
    > elaborates
    > doesn't leave you out
    u r the best bro

  • @jess_jenicca
    @jess_jenicca 2 หลายเดือนก่อน

    your way of explaining is top tier!

  • @Fadingsupernova
    @Fadingsupernova 2 หลายเดือนก่อน

    Ive learned more from you , than I ever did through my qualification courses.

  • @KhansaSaqib
    @KhansaSaqib 21 วันที่ผ่านมา

    great explanation of math.random()method

  • @umloiro3219
    @umloiro3219 7 หลายเดือนก่อน +1

    4 min so good :D thanks for the info

  • @robertoaraujo6367
    @robertoaraujo6367 ปีที่แล้ว

    This was really helpful, thank you.

  • @SONICBOY_
    @SONICBOY_ ปีที่แล้ว +2

    I think math.ceil()is wanted to use there because then we don't want to add 1

  • @MohyDev
    @MohyDev 2 ปีที่แล้ว +6

    //For the algorithm!

  • @Dynamicsimpson
    @Dynamicsimpson ปีที่แล้ว

    This was a great video, as it helped correct me in doing a similar task. Thank you!

  • @MC_FortunaCraft
    @MC_FortunaCraft ปีที่แล้ว

    Thx that was simple and helpful

  • @AlessandroManente
    @AlessandroManente ปีที่แล้ว +1

    "I like to play lot of D&D"... insta-subscribed 😅 Thanks so much for the JS tutorial!

  • @nontandohappiness6382
    @nontandohappiness6382 8 หลายเดือนก่อน

    Thank you!!😊

  • @Penzisloading69
    @Penzisloading69 ปีที่แล้ว

    Super useful, Thanks a lot

  • @user-yh4rf9oc4g
    @user-yh4rf9oc4g 9 หลายเดือนก่อน

    nice lecture

  • @tommyho1313
    @tommyho1313 ปีที่แล้ว

    thank you so much!! t's very helpful,

  • @mateo-ml7lt
    @mateo-ml7lt ปีที่แล้ว

    Its really helped me, bro😃

  • @somkumar4827
    @somkumar4827 10 วันที่ผ่านมา

    amazing video

  • @tazul8
    @tazul8 ปีที่แล้ว

    Helpful tutorial. Thanks...

  • @jaredkaye3669
    @jaredkaye3669 6 หลายเดือนก่อน

    Hmm I wanted to know how math.random() selects the number.
    In WoW /roll would give the dice roll for loot and casinos. I thought it was derived from the time frequency.
    CLA3 AI is describing itself with javaScript and math.random().

  • @sahilsoni6191
    @sahilsoni6191 ปีที่แล้ว

    Broskies are always there to help !!

  • @MrLoser-ks2xn
    @MrLoser-ks2xn ปีที่แล้ว

    Thanks!

  • @hoatranminh5216
    @hoatranminh5216 ปีที่แล้ว

    Thank you so much, Bro

  • @lucabinder9829
    @lucabinder9829 2 ปีที่แล้ว +1

    Thats Brolicious!

  • @TheEvertonDias
    @TheEvertonDias ปีที่แล้ว

    Thanks, Bro!

  • @spacekeebeats3155
    @spacekeebeats3155 11 หลายเดือนก่อน

    thank you

  • @ibrahimhossen6549
    @ibrahimhossen6549 3 หลายเดือนก่อน

    Nice

  • @galveraymundp.2520
    @galveraymundp.2520 ปีที่แล้ว

    what if I want it to have two input box where you can put the maximum and minimum that will generate 6 random numbers (EXAMPLE : Min: 1 Min:2 *press generate button Output: 2,1,3,5,7,6)
    please help🙂

  • @jobarmure6169
    @jobarmure6169 ปีที่แล้ว

    thx for your help

  • @AnjoSoy
    @AnjoSoy 2 ปีที่แล้ว

    Hey Bro, thank you! =D

  • @henningbotha777
    @henningbotha777 19 วันที่ผ่านมา

    Thx Bro!

  • @A1exP1ays
    @A1exP1ays ปีที่แล้ว +1

    when he rolled 5 5 times in a row its a 1 in 7776 chance (thanks calculator)

  • @francheeze
    @francheeze ปีที่แล้ว

    You can just use Math.ceil(Math.random() * 6) instead

  • @singh-vx9hx
    @singh-vx9hx ปีที่แล้ว

    how to add the number just using one time math.floor. Suppose first time it gives 5 and next time it five 6 ...I want to add them by only using one time math.floor........how to store them and add them

  • @scpf2360
    @scpf2360 2 ปีที่แล้ว +4

    It Did Not Work :(

    • @oximas-oe9vf
      @oximas-oe9vf ปีที่แล้ว

      try again it will work
      try copying his code to see if the problem is with your the code or with your IDE

  • @Gio-gafro
    @Gio-gafro 2 หลายเดือนก่อน

    Thx

  • @remidis
    @remidis ปีที่แล้ว +1

    awesome, now every java game developers could make a gacha game and start milking their players' wallet

  • @TheVinfather
    @TheVinfather 2 ปีที่แล้ว +1

    I am already a bro😂😂

  • @roycechriston5389
    @roycechriston5389 2 ปีที่แล้ว

    Let's freaking goooo 👻

  • @ngocthangphan8968
    @ngocthangphan8968 ปีที่แล้ว

    instead of pressing roll 10 times, is there a way to print to the screen with the data 10 times?

  • @alexdin1565
    @alexdin1565 2 ปีที่แล้ว

    you are the best

  • @talstolo50
    @talstolo50 11 หลายเดือนก่อน

    i copied the exact same codes but its not working for me

  • @temotemo-lw2du
    @temotemo-lw2du ปีที่แล้ว

    when you making plus 1 its random number between 1 and 7 and you didnt explain how to find numbers for example beteween 20 and 60

  • @amazingmoments7690
    @amazingmoments7690 5 หลายเดือนก่อน

    Hi, i am looking for a code for generating unique username on registration form so pls advise.

  • @Spunky_Tx
    @Spunky_Tx 2 หลายเดือนก่อน

  • @ViReel9436
    @ViReel9436 2 ปีที่แล้ว +1

    What's the seed used here?

    • @lolplayfelix-_-2713
      @lolplayfelix-_-2713 2 ปีที่แล้ว +4

      depends on the browser and the architecture, in most cases, you can't really tell...
      digging through the v8 engine source code i found a lot of different ways they create random numbers, so as far as i can see, you'll have to create your own seeded random function, a good starting point would be something called a "linear feedback shift register" and maybe some of your own implementations (just from the top of my head you could hash the seed you got, and interpret that as a value from 0 to 1)

  • @KamiNoKam
    @KamiNoKam 2 ปีที่แล้ว

    How can I add preset variables? Like 1-6 but the odds of getting 6 is more.

    • @harshjha4451
      @harshjha4451 2 ปีที่แล้ว

      😂

    • @Gubei01
      @Gubei01 ปีที่แล้ว

      im wondering that too, should probably search on google

    • @crazzykai
      @crazzykai ปีที่แล้ว +1

      probably roll something like 1 - 12 but then make it if it's bigger than 6 it will round to 6

  • @IzEFunni
    @IzEFunni ปีที่แล้ว

    How would you put this in a discord bot?

  • @Akgaming-games
    @Akgaming-games 2 ปีที่แล้ว

    can you make a video on python full course latest version

    • @rayankhan12
      @rayankhan12 2 ปีที่แล้ว +1

      Um.. the 12 hour video on his channel is already latest version??

    • @Akgaming-games
      @Akgaming-games 2 ปีที่แล้ว

      @@rayankhan12 that is 1 year old

    • @haygetheh
      @haygetheh 2 ปีที่แล้ว

      As someone who currently follows the guide, most classes in the course work on the latest version. Currently at a 2 hour point of the whole thing but i couldn't do only one lesson, that being dictionaries.

    • @rayankhan12
      @rayankhan12 2 ปีที่แล้ว

      @@Akgaming-games But it isn't easy to make another (more or less) 12 hour video on Python again.

    • @canwegetashoutouttoworking2002
      @canwegetashoutouttoworking2002 2 ปีที่แล้ว +1

      @Dude, I am not an alien... If you're talking about javascript, try this out:
      function random() {
      let variable = Math.floor(Math.random() * 9) + 1;
      alert("Your random number is " + variable);
      }
      You can repeat this as much as you want to.

  • @clrkkdd12
    @clrkkdd12 2 ปีที่แล้ว

    👊🏽

  • @bilaltoumir4475
    @bilaltoumir4475 2 ปีที่แล้ว +1

    Please do php

    • @oximas-oe9vf
      @oximas-oe9vf ปีที่แล้ว

      I am voting for PHP as well

  • @randomletters1834
    @randomletters1834 ปีที่แล้ว

  • @larissacury7714
    @larissacury7714 ปีที่แล้ว

    Thank you!! 😄