Facebook – https://www.facebook.com/TheNewBoston-464114846956315/ GitHub – https://github.com/buckyroberts Google+ …



  1. I made this ..
    #include <cmath>
    #include <cstdlib>
    #include <ctime>
    #include <iostream>

    using namespace std;

    int main(){
    int y;
    int p = 0;
    string s;
    cout << " >>>>> MINI CASINO <<<<< " << endl;
    cout << "CASINO : Hey! Enter a number between 1 to 10 . Let's see if your number matches with mine .." << endl;
    cin >> y;
    int x = 1+(rand()%10);
    int z = 1+x;
    cout << "Congratulation!! You won" << endl;
    cout << "Didn't Match! Enter again n";
    cin >> y;

    case 1:
    s = "attempt";
    s = "attempts";
    cout << "CASINO : Excellent! You just made it in " << p << " " << s <<" .. " << endl;
    cout << "CASINO : You made it in " << p << " "<< s <<" . Your luck really needs improvement pal.. " << endl;

    I dont know why but i'm getting the same number each time i run it!!!!
    All 25 numbers are same!!!!
    I also wanted to know how to make this rand() an int so i could use it in my do while loop

  3. I want to generate a no. from a given list like i want a random no. from {1,2,4,6},
    is there any function for this?Please answer

  4. anybody here know the algorithm to this rand function? if anybody knows please give me a link to a site so i can learn about it or please share with me

  5. For the people who come across this video in the future, since it is one of the most viewed tutorials on random numbers in C++, I feel the need to give a warning.
    rand() is historically a terrible source of random numbers. The numbers it gives are potentially non-uniform (some numbers may appear more often than others), on some platforms rand() only produces numbers up to 2^16 – 1, so if you need a random number greater than 33000, you're out of luck, and if you need a lot of random numbers, you'll find it will start repeating the sequence it has already given you.
    Using % to shrink the range is also an awful idea. Even if rand() didn't give awful random numbers, using % will often introduce bias in your results too (higher numbers can become less likely to appear).

    If you just need something vaguely random, then this tutorial will be sufficient. If you want decent randomness, I recommend looking for turorials on how to use C++'s <random> header. If you need randomness for security purposes, you probably shouldn't be watching introductory videos on C++. :p

  6. I want an pseudo random number generator that can generate numbers with no repeats in a random order.

    For example:


    might return
    5, 9, 1, 4, 2, 8, 3, 7, 6, 10

    Is there a better way to do it other than making the range of numbers
    and shuffling them about, or checking the generated list for repeats?

  7. I've been watching your C and C++ tutorials for some time now. When I don't fully understand something from my programming books, your videos are the go to videos to complement what I'm currently learning. Thank you!!

Leave A Reply

Please enter your comment!
Please enter your name here