source

1. What if we need to make a random number more often than every second?

2. thanks !!

#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;
srand(time(0));
int x = 1+(rand()%10);
int z = 1+x;
while(x<z){
if(x==y){
cout << "Congratulation!! You won" << endl;
x++;
}else{
cout << "Didn't Match! Enter again n";
cin >> y;
}
p++;
};

switch(p){
case 1:
s = "attempt";
break;
default:
s = "attempts";
}
if(p<=3){
cout << "CASINO : Excellent! You just made it in " << p << " " << s <<" .. " << endl;
}else{
cout << "CASINO : You made it in " << p << " "<< s <<" . Your luck really needs improvement pal.. " << endl;
}
};

4. watermelon

5. you are randomly amazing.
keep it UP

6. A PROBLEM AND A QUESTION PLS ANSWER : )
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

7. I want to generate a no. from a given list like i want a random no. from {1,2,4,6},

8. 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

9. Why the argument of 'time' is zero? What does it mean?

10. what if we use srand( time ( 4 ) );
i mean any other number than 0 …?

11. How how you do this with numbers of type double?

12. Instead of – cout << 1+(rand() % 6) << endl; you can do – cout << rand() % 6 + 1 << endl.

13. 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

14. How do you make it put the random number into a variable??

15. How do you make it put the random number into a variable??

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

For example:

random(10)

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?

17. Hi, Bucky, congrats for this works. I hava a questions about the number 5, what is the case?. Greetings.

18. Why 0 inside the parenthesis of time function?

19. 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!!

20. thankyou 🙂