Generating Random Numbers in C++: Exploring rand(), srand(), and time() Functions [Tutorial] [8]

Поділитися
Вставка
  • Опубліковано 8 січ 2025

КОМЕНТАРІ • 48

  • @Leonidnrv
    @Leonidnrv Місяць тому +1

    Having a hard time to understand srand and why we need to change the seed. Now it's clear. Thank you!

  • @leythecg
    @leythecg Рік тому +9

    Once again brought to the point without much fuss! Thank you very much! 👍👍👍

    • @ProfessorHankStalica
      @ProfessorHankStalica  Рік тому +2

      Glad it was helpful!

    • @abel1340
      @abel1340 10 місяців тому

      @@ProfessorHankStalica thank you professor!on point! like the hat!

  • @pelecaj7067
    @pelecaj7067 11 місяців тому +5

    short and to the point. thanks

  • @officialdanieldsouza
    @officialdanieldsouza 5 місяців тому +1

    Excellent tutorial! I tried to understand the same concept through reading some blog articles online but didn't fully grasp the concepts that you discussed in clear, simple level of understanding in this video.
    Thanks again!!

  • @duttybwoy556
    @duttybwoy556 6 місяців тому +1

    Very good , clear and simple explanation !!! good job...
    I also saw this line srand(time(NULL)); on top of the main function for this to not generate the same number all the time

  • @safa-uc1mk
    @safa-uc1mk Рік тому +5

    Thank you mister! That was a really crisp explanation 🙌

  • @EbyHamady-ul7rc
    @EbyHamady-ul7rc Рік тому +3

    It was a really excellent and calm explanation, thank you

  • @HarisAbdullah-p6t
    @HarisAbdullah-p6t 3 місяці тому

    Sir, Thank you so much.
    It helped a lot.
    Lots of love and thanks from Pakistan.

  • @carljohncafe6921
    @carljohncafe6921 8 місяців тому +1

    Thank you so much! This video is a life saver.

  • @ExamYou-q3i
    @ExamYou-q3i 2 місяці тому

    wow !!!! like i couldnt even understand it from chat gpt!!!!! but you made it look so easy like a sittng duck. thank you sooo much

    • @ProfessorHankStalica
      @ProfessorHankStalica  2 місяці тому

      The funny thing about ChatGPT is that it's wrong. A lot. Don't depend on it for school work. 1. It's cheating. 2. You won't learn anything. 3. It's wrong a lot.

  • @andrewbooher1709
    @andrewbooher1709 10 місяців тому +1

    How would you go about reading a user input in the range of numbers? For example, if you wanted them to pick a number 1 - 10. How could you make it so it reads if they picked within that range?

  • @lydianne8013
    @lydianne8013 Рік тому +1

    Thank u so much i have an exam tomorrow and i don't understand this function . U save me ❤❤

  • @ZorikaSakamishi
    @ZorikaSakamishi 5 місяців тому +1

    Thanks sir i appreciate your work

  • @sianwa11
    @sianwa11 8 місяців тому

    Thanks for the clear explanation

  • @23Devvrat
    @23Devvrat 9 місяців тому

    great video man ! cheers

  • @luisochoa5282
    @luisochoa5282 Місяць тому

    My guy is saving lives without knowing it

  • @jchdbtcmdddhuryy6332
    @jchdbtcmdddhuryy6332 6 місяців тому

    Thank so much ❤

  • @juanyeclay
    @juanyeclay Місяць тому

    damn good video bro

  • @Knochentod
    @Knochentod 25 днів тому

    Is it possible to save the numbers and then calculate with them or something?

    • @ProfessorHankStalica
      @ProfessorHankStalica  21 день тому

      Sure. Place them in a variable and then use the number for whatever you need it for.

  • @omarmohammed9938
    @omarmohammed9938 11 місяців тому

    So if I wanted to generate random number from 0 to 12
    Then i do this right?
    Cout

    • @ProfessorHankStalica
      @ProfessorHankStalica  11 місяців тому +1

      Close. rand() % 13 because of how modulus works. If you divide any number by 13 by, the remainder will be any integer from 0 - 12.

  • @brigadut
    @brigadut Місяць тому

    int x = time(NULL);
    srand(x);
    int range = 100;
    int randomNumber = (rand() + 1) % range;
    std::cout

  • @Wagonik
    @Wagonik Рік тому

    thx! very useful

  • @youssefkawtharani2536
    @youssefkawtharani2536 Рік тому

    What if i want the user to enter a random number and the program should tell true or false?

  • @volkwell-wk3eq
    @volkwell-wk3eq 10 місяців тому

    "cstidlib"
    I laughed

  • @M7medKasem
    @M7medKasem Рік тому +1

    You look charismatic, however can pull off the goofiest face in the party at anytime.

    • @ProfessorHankStalica
      @ProfessorHankStalica  Рік тому +1

      Now, if only the ladies thought so, I'd be in business... 👍🤣😂

    • @M7medKasem
      @M7medKasem Рік тому

      @@ProfessorHankStalica you're the cool professor in college for sure 🫶🫶😂

    • @ProfessorHankStalica
      @ProfessorHankStalica  Рік тому +2

      @@M7medKasem Well, far be it from me to argue with someone with such obvious intelligence!

  • @yooniecardbtsclips
    @yooniecardbtsclips Рік тому

    Thankssss

  • @hosseinbachari6732
    @hosseinbachari6732 4 місяці тому +1

    Thanks , your voice is a little low

  • @Aarpod
    @Aarpod 11 місяців тому

    You shoulda wrote the textbook im using for class right now. I don’t know how the author is gonna just drop rand/srand in an example program without context and be like:
    “Edit the program so it displays 1-10”
    Like nah thats not how it works chief