Generating a random number in javascript

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.ย. 2024
  • Welcome to a youtube channel dedicated to programming and coding related tutorials. We talk about tech, write code, discuss about cloud and devops. That’s what we do all day, all year. We roll out a lot of series and videos on our channel.
    All the learning resources such as code files, documentations, articles and community discussions are available on our website:
    chaicode.com/
    You can find our discord link, github link etc on the above website.
    Twitter/X link: x.com/hiteshdo...
    Discord link: hitesh.ai/discord
    Learn React with 10 projects: • Let's learn react from...
    Learn Docker: • A practical guide on D...
    Learn Kubernetes: • Complete Kubernetes Co...
    How does a browser works: • How does a browser wor...
    How nodejs works: • How node JS works | En...
    Learn Redux-toolkit: • Learn Redux Toolkit in...
    Learn NextJS: • Nextjs Full stack course
    Learn Typescript: • Why to learn Typescript
    Learn Javascript: • Welcome to new JavaScr...
    Learn React Native: • React Native Mastery: ...
    Learn Zustand: • React state management...
    Learn Golang: • How to get started wit...

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

  • @edugetters
    @edugetters 5 ปีที่แล้ว +10

    You are so great teacher. Your work is highly appreciable.

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

    Thank you for the tutorial! Coming from Python, the start/end looks complex VS:
    import random
    dice = random.randrange(20, 26)

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

    ceil and floor are actually other names for Lowest Integer Function and Greatest Integer Function

  • @manojkumarm8398
    @manojkumarm8398 4 ปีที่แล้ว

    Never Seen a Teacher like u✔

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

    let floatRes = Result
    can also bring the same output, no neet to write to.Fixed(2) for twice. at 5:12

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

    Hi Hitesh, great to follow your videos.I am learning a lot from these videos.Thanks a lot!!
    Here I have written a very simple game.I want to share the code
    let userTurn=function(){
    let user = Number(prompt('enter a random number'));
    return user;
    }
    let computerTurn=function(){
    let system = Math.floor(Math.random()*10);
    return system;
    }
    for(i=1;ib){
    console.log('user wins');
    }
    else{
    console.log('computer wins');
    }
    }
    What do you say about the code and how can I make it better.
    Thanks in advance.

  • @nishantghosh3513
    @nishantghosh3513 4 ปีที่แล้ว

    we should use round() for get its​ closest integer so why we use floor or ceil

  • @madhusudankowlgi1113
    @madhusudankowlgi1113 6 ปีที่แล้ว

    Hitesh, your concept of viewing and doing is too good. Examples you have selected are excellent, easy to understand. Technically to the point. Hope to see more in further videos

  • @shankumondal2881
    @shankumondal2881 4 ปีที่แล้ว

    You are not a programmer , you are a magician

  • @gbktechnologies6637
    @gbktechnologies6637 3 ปีที่แล้ว

    23 video u ask subscribe , just now i did that. awesome videos .....life time videos

  • @abhishek_dam
    @abhishek_dam 3 ปีที่แล้ว

    that was quite a good explanation man thank you I have been looking so much but couldn't find any except yours. thanks again

  • @ovirex
    @ovirex 5 ปีที่แล้ว

    Thanks man, I was looking for this because I didn't understand how it works but you explain it very well and simple. Greetings from Venezuela.

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

    Thank you.. Now I understand the formula..

  • @hometv4061
    @hometv4061 3 ปีที่แล้ว

    it was 1:30 in the morning and you were making videos for us

  • @Technoholicplus
    @Technoholicplus 4 ปีที่แล้ว

    let upper = 1;
    let lower = 10;
    if (upper > lower) {
    let randomizer = function(up, low) {
    let myRandom = Math.random() * (up - low);
    let final = myRandom + 20;
    return `the random value inclusive of ${upper} and ${lower} is ${Math.round(
    final
    )}`;
    };
    console.log(randomizer(upper, lower));
    } else if (upper === lower) {
    console.log("Upper Lower can't be same");
    } else {
    console.log("Upper value cannot be smaller than Lower");
    }
    Thanks, bro I used Math.round to include both upper limit and lower limit.

  • @Bajrang.707
    @Bajrang.707 5 ปีที่แล้ว +2

    This is really cool one!
    And you''re the great mentor for us!

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

    such an interesting video, looking for it quite long time . lotsOfLove keep rocking Hitesh , 'm on my mac cant put smiles here please take all my wishes

  • @stealthbusiness
    @stealthbusiness 4 ปีที่แล้ว

    Thanks for putting the tutorial together. :)
    Is there a way to Password Protect online videos (TH-cam, Vimeo... etc) with some if not all of these features?
    Random Password
    Set the Expiration time or date
    Set the Total time a video can be viewed
    Set how many times the password is allowed
    Setup Password Groups
    I know it's asking a lot, if you're busy, I understand. You seem to have the skills to make it happen. Just putting it out there.

  • @harjapx
    @harjapx 5 ปีที่แล้ว

    Instead of Math.Floor, if we provide '0' value to the toFixed it still shows integer value without any decimal places then what's the point of using the Math.floor?
    Please explain...

  • @monikanb6120
    @monikanb6120 4 ปีที่แล้ว

    Wow I really enjoii this series

  • @vinaymanikant9710
    @vinaymanikant9710 6 ปีที่แล้ว

    Loving this series alot
    Hoping to have a complete bunch of JS series
    And sir please give alot of projects along with them

  • @YoYo-eg6rc
    @YoYo-eg6rc 5 ปีที่แล้ว +1

    Thanks you sir , I clearly understand How it work

  • @hackx_hive8221
    @hackx_hive8221 6 ปีที่แล้ว +3

    Your dedication really inspires..!👌👍🏼

  • @avisheksinha4264
    @avisheksinha4264 6 ปีที่แล้ว +3

    Thanks sir for this video 😊

  • @manuchowdary7848
    @manuchowdary7848 4 ปีที่แล้ว

    Finally my confusion was clear

  • @unyieldingjarnail
    @unyieldingjarnail 5 ปีที่แล้ว

    Always nice stuffs from you. And I want to know if you can share your system configuration pls

  • @selimatasever4112
    @selimatasever4112 5 ปีที่แล้ว

    Thanks bro.. i liked the way you explain the details. Subscribed!!

  • @srikantdas2523
    @srikantdas2523 6 ปีที่แล้ว

    It's really an awesome tutorials for beginners. I am going to subscribe it.

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

    i can;'t wrap my head around the fact that i would have never been able to write this function from the top of my head

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

      yeah well, im back! and this looks way too easy. Ive used the math.random function in more complicated functions such as color and string generators. Don't give up!

  • @mdmoinmoin8888
    @mdmoinmoin8888 6 ปีที่แล้ว

    love your teaching keep uploading videous like even if u dont get many views later on but many really watch all of it

  • @anil0407
    @anil0407 6 ปีที่แล้ว

    let message = "I love the tutorial";
    if(message)
    {
    console.log(message);
    }
    thank you sir. I am enjoying your tutorial.

    • @HiteshCodeLab
      @HiteshCodeLab  6 ปีที่แล้ว

      Thanks

    • @dikshitkaushik8387
      @dikshitkaushik8387 6 ปีที่แล้ว

      bhai there is no need if if else statement and u not use properly that if else statement stuff

    • @sanudajayathilaka3173
      @sanudajayathilaka3173 5 ปีที่แล้ว

      @@dikshitkaushik8387 nothing wrong with the code bro. He has checked whether the message is exist? if its true return message. He has done a wonderful job

  • @shawnedits161
    @shawnedits161 4 ปีที่แล้ว

    sir how we can genreate random number in a given range without using math.Random() in javascript

  • @nithsua
    @nithsua 5 ปีที่แล้ว

    And this series is really awesome

  • @ShubhamSharma-rm9ry
    @ShubhamSharma-rm9ry 6 ปีที่แล้ว

    sir, i like this video as compare to random password generator project.

  • @StarDoesntUpload
    @StarDoesntUpload 5 ปีที่แล้ว

    22/7 is not Pi, it’s just close to Pi. Pi is an infinitely long string of numbers, and is therefore impossible to write as a fraction.

  • @aurangzaibmanzoor1136
    @aurangzaibmanzoor1136 3 ปีที่แล้ว

    how to stop generating the same random numbers with the database I want to generate roll numbers which should not be same so tell me.

  • @jackfrost8969
    @jackfrost8969 5 ปีที่แล้ว

    this is beyond perfect.
    thanks a ton.

  • @yeswanthchintapalli7144
    @yeswanthchintapalli7144 6 ปีที่แล้ว

    I NEED PANCARD VALIDATION THROUGH THE TEXTBOX THAT 5TH CHARACTER IN PANCARD NUMBER MUST MATCHES WITH THE SURNAME

  • @aWiseCoder
    @aWiseCoder 5 ปีที่แล้ว

    Thanks I understand The concept now

  • @KK-wd5nc
    @KK-wd5nc 6 ปีที่แล้ว

    sir , wud u please tell us tht how to make dynamic img slider using JS ??????

  • @sonudeep6472
    @sonudeep6472 4 ปีที่แล้ว

    But sir I have also got 0 .... sir what is the reason... please reply

  • @2002utube
    @2002utube 5 ปีที่แล้ว

    I think you are a developer...may be you know which are the mostly used all functions in Math lib . May be this will be useful. Because there are many in the documentation.

  • @abdullahalrifat4997
    @abdullahalrifat4997 3 ปีที่แล้ว

    Thanks

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

    Result = 22/7
    But u have forgot to put let or var before result...
    But you got correct answer..How}??

    • @michaelobeng7660
      @michaelobeng7660 5 ปีที่แล้ว

      in javascript if you do not declare var or let the variable is still accessible and it becomes a global variable

    • @YoYo-eg6rc
      @YoYo-eg6rc 5 ปีที่แล้ว

      @@michaelobeng7660 yes you are true

    • @shreejasoni5171
      @shreejasoni5171 4 ปีที่แล้ว

      watch his viedoe of var and let he is telling local and global

  • @HarpreetKaur-pm3so
    @HarpreetKaur-pm3so 6 ปีที่แล้ว +1

    "THE" best :)

  • @manuchowdary7848
    @manuchowdary7848 4 ปีที่แล้ว

    Thanku

  • @thangathirupathi7257
    @thangathirupathi7257 4 ปีที่แล้ว

    thank you

  • @chandanbaruah7692
    @chandanbaruah7692 6 ปีที่แล้ว

    concept clear thanks

  • @EVOLUTIONSHORTSs
    @EVOLUTIONSHORTSs 4 ปีที่แล้ว

    Can u create website for me i want to hire u as developer?

  • @ruhankhandaker5198
    @ruhankhandaker5198 6 ปีที่แล้ว

    wao,, Another great video.

  • @sulbhasharma92
    @sulbhasharma92 6 ปีที่แล้ว

    please also give series lyk this for node n react js too

    • @HiteshCodeLab
      @HiteshCodeLab  6 ปีที่แล้ว

      Available here
      courses.learncodeonline.in

  • @ShubhamGupta-qb4gu
    @ShubhamGupta-qb4gu 4 ปีที่แล้ว

    Smallest Code
    let a = Math.ceil(Math.random()*6);
    console.log(a);

  • @samosrecaipozitiva1764
    @samosrecaipozitiva1764 4 ปีที่แล้ว

    Thank you you are great !

  • @babaji0997
    @babaji0997 6 ปีที่แล้ว

    Thank you so much sir......

  • @joshiadvait8
    @joshiadvait8 6 ปีที่แล้ว

    *Just because you started this series your subscribers got increased a lot
    I think You should put some more free series on react native & database connectivity with same as well it will increase subscribers in Huge nos*

    • @HiteshCodeLab
      @HiteshCodeLab  6 ปีที่แล้ว +5

      Check again. Views on regular videos is high and views on JS series is so low. Anyways, these numbers are just numbers. I am just looking to move forward.

  • @mohdsadique551
    @mohdsadique551 4 ปีที่แล้ว

    I dont know why did you take this long route, i think you could have simply showed us :
    let dice = Math.floor(Math.random()*6)+1
    and its done.

    • @shreejasoni5171
      @shreejasoni5171 4 ปีที่แล้ว

      maybe he is trying to teach upper and lower concept.
      btw I got output by using Math.floor(Math.random()*6)+1 thanku

  • @RakeshSharma-df2ie
    @RakeshSharma-df2ie 6 ปีที่แล้ว

    Hello sir can you please explain me this code
    //generate random numbers between 83 to 93
    let upper = 93;
    let lower = 83;
    let randomNum = Math.ceil(Math.random() *(upper - lower)) + lower;
    console.log(randomNum);

    • @RainOnline
      @RainOnline 5 ปีที่แล้ว

      93 - 83 = 10 . so you random a number from 0 to 10. and the end "+lower" means 83. , which means you random a number from 83 to 83 +10 which is 93, and result is 83 to 93

    • @hardik.motwani
      @hardik.motwani 5 ปีที่แล้ว

      You have used ceil so range will be from 1 to 10, + lower will make the range 84 to 93

  • @chetask4558
    @chetask4558 5 ปีที่แล้ว

    math.random() * 5+1 doesn't gave 0 value how to deal with that

  • @abazur7742
    @abazur7742 5 ปีที่แล้ว

    9:52 starts talking about random

  • @subhranil764
    @subhranil764 5 ปีที่แล้ว

    Nice sir:)

  • @ANOOPKUMAR-cu2eo
    @ANOOPKUMAR-cu2eo 6 ปีที่แล้ว

    thanks sir

  • @Srestha2023
    @Srestha2023 4 ปีที่แล้ว

    why can't we just use math.ceil on math.random()*6

    • @shreejasoni5171
      @shreejasoni5171 4 ปีที่แล้ว

      can you please elabore by which i can try

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

  • @ovirex
    @ovirex 5 ปีที่แล้ว

    Figura del partido

  • @danyrupesarputharaj6969
    @danyrupesarputharaj6969 6 ปีที่แล้ว

    yes sir

  • @yoyoma7273_6
    @yoyoma7273_6 5 ปีที่แล้ว

    Why don't we need to import math first?

  • @_ghost_69.
    @_ghost_69. 4 ปีที่แล้ว

    Well random in python is easy than js

  • @VIKASGUPTA-ec1kd
    @VIKASGUPTA-ec1kd 4 ปีที่แล้ว +1

    who is here in 2020-corona panademic ?

  • @Ashish-es4nk
    @Ashish-es4nk 6 ปีที่แล้ว

    Thanks Hitesh for being awesome. I just created a function for random and let me know what you think?
    jsbin.com/comuruh/edit?js,console

  • @jibinbaby5030
    @jibinbaby5030 4 ปีที่แล้ว

    That was not tricky at all sir. Catched in the very first exercise.

  • @prabu2778
    @prabu2778 4 ปีที่แล้ว

    I think you are working in google

  • @konstantinpavlovic8472
    @konstantinpavlovic8472 5 ปีที่แล้ว

    2:35 :DDDDDD

  • @nithsua
    @nithsua 5 ปีที่แล้ว

    do you love maths? cuz i hate it

  • @dsaha7473
    @dsaha7473 6 ปีที่แล้ว

    😂😂

  • @dahabodarman6012
    @dahabodarman6012 5 ปีที่แล้ว

    thank you