If so, what's its purpose. and 2) why is it necessary to add 1 after your max is decreased by one, what is the purpose of that also? any help would be appreciated :D
@brawl313 It's not necessary to put 1, I only put it because I want the random number generator to pick values starting from the number 1, otherwise it would start from 0.
hey again, lol. I have a little question I'm not 100% sure about. How does (rand() % max) + 1 work again? so you said rand() % max would give out whatever your maximum number is but one less because of the % operator, then you would need to add one. 2 questions. 1) why does the % take up 1 number space because I thought 5%2 meant like 5/2 which is 1, but rand is just random, or does the % mean 2 different things in the program.
@brawl313 rand() works by giving you a value between 0 and 1 (meaning decimals). And getting the remainder by dividing by 'max' gives you the whole number value and adding 1 to that means the results will be between 0 and 100 (or whatever the max value is.
just to make things clear the ctime is when you want to work a program using time (eg: as you previously said about displaying a number every second, but as far as you wrote this program it doesn't do this kind of work, so if i don't use the ctime library it won't matter in this kind of situation, right?
and the cstdlib it's when you want to use something random, in this kind of situation a number, right? :D
i hope that someone replies back soon, i have got a test in 2 days >.<
@radiodjcy ctime is there for the time() function and that runs to basically reset the clock, and if you don't use it in this program, the likelihood of the program generating a random number decreases as more numbers are outputted because without resetting, the program may not spit out the same number again until it's restarted. It's not with all compilers so it's open to how people see it. Otherwise, you're right :)
@HardkoreRocker thank you :) and yes, the rand() % max should be inside parenthesis. Well actually, it should work either way since the mod function comes before addition, I just use parenthesis because it's neater :)
@ImperviouS16 No, I said it should reset the value every second because if it doesn't reset, it won't pick the same number twice until it's reset or you exit the program - which wouldn't be random.
If you want to display a random value every second, then you can do that with some extra codes and a while or do while loop, but this program wasn't meant to do so.
Thanks dude!
singoutloud2utube 2 weeks ago
If so, what's its purpose. and 2) why is it necessary to add 1 after your max is decreased by one, what is the purpose of that also? any help would be appreciated :D
brawl313 1 month ago
@brawl313 It's not necessary to put 1, I only put it because I want the random number generator to pick values starting from the number 1, otherwise it would start from 0.
njoker555 1 month ago
hey again, lol. I have a little question I'm not 100% sure about. How does (rand() % max) + 1 work again? so you said rand() % max would give out whatever your maximum number is but one less because of the % operator, then you would need to add one. 2 questions. 1) why does the % take up 1 number space because I thought 5%2 meant like 5/2 which is 1, but rand is just random, or does the % mean 2 different things in the program.
brawl313 1 month ago
@brawl313 rand() works by giving you a value between 0 and 1 (meaning decimals). And getting the remainder by dividing by 'max' gives you the whole number value and adding 1 to that means the results will be between 0 and 100 (or whatever the max value is.
njoker555 1 month ago
you've really helped me, thank you
TheJata93 1 month ago
just to make things clear the ctime is when you want to work a program using time (eg: as you previously said about displaying a number every second, but as far as you wrote this program it doesn't do this kind of work, so if i don't use the ctime library it won't matter in this kind of situation, right?
and the cstdlib it's when you want to use something random, in this kind of situation a number, right? :D
i hope that someone replies back soon, i have got a test in 2 days >.<
radiodjcy 3 months ago
@radiodjcy ctime is there for the time() function and that runs to basically reset the clock, and if you don't use it in this program, the likelihood of the program generating a random number decreases as more numbers are outputted because without resetting, the program may not spit out the same number again until it's restarted. It's not with all compilers so it's open to how people see it. Otherwise, you're right :)
njoker555 3 months ago
Awesome man ur DA SHIT !
Pendragonthegreat 3 months ago
if you're taking part in a contest on programming be sure to not use system("pause") .
better would be:
char z;
cin >> z;
return 0;
realXipaN 3 months ago
my number is always 2686792 for some reason
159kira 4 months ago
@159kira you can send me your code if you'd like, I can take a look to see if anything is wrong.
njoker555 4 months ago
Thanks!
kylejack1 7 months ago
(rand () % max) + 1 .....????? that inside parenthesis ?? u seem to always answer all my doubts bro!!! your videos r awesome
HardkoreRocker 11 months ago
@HardkoreRocker thank you :) and yes, the rand() % max should be inside parenthesis. Well actually, it should work either way since the mod function comes before addition, I just use parenthesis because it's neater :)
njoker555 11 months ago
Shouldn't it have outputted the numbers automatically every second as you said?
ImperviouS16 11 months ago
@ImperviouS16 No, I said it should reset the value every second because if it doesn't reset, it won't pick the same number twice until it's reset or you exit the program - which wouldn't be random.
If you want to display a random value every second, then you can do that with some extra codes and a while or do while loop, but this program wasn't meant to do so.
njoker555 11 months ago
@njoker555 Oh, my bad. I guess I misunderstood. :)
ImperviouS16 11 months ago
@ImperviouS16 no prob :) glad I could clear it up for you.
njoker555 11 months ago
THANKS!
Jeremiahfuzz 1 year ago
@Jeremiahfuzz you're welcome :)
njoker555 1 year ago
Error 1 error C3861: 'strand': identifier not found
please help
Jeremiahfuzz 1 year ago
@Jeremiahfuzz well it's srand, there is no 't' in there.
njoker555 1 year ago
@Jeremiahfuzz It's srand not strand!
Bleachlover214 11 months ago