Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (24)

Sign In or Sign Up now to post a comment!
  • Thanks dude!

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

  • you've really helped me, thank you

  • 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 :)

  • Awesome man ur DA SHIT !

  • 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;

  • my number is always 2686792 for some reason

  • @159kira you can send me your code if you'd like, I can take a look to see if anything is wrong.

  • Thanks!

  • (rand () % max) + 1 .....????? that inside parenthesis ?? u seem to always answer all my doubts bro!!! your videos r awesome

  • @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 :)

  • Shouldn't it have outputted the numbers automatically every second as you said?

  • @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 Oh, my bad. I guess I misunderstood. :)

  • @ImperviouS16 no prob :) glad I could clear it up for you. 

  • THANKS!

  • @Jeremiahfuzz you're welcome :)

  • Error 1 error C3861: 'strand': identifier not found

    please help

  • @Jeremiahfuzz well it's srand, there is no 't' in there.

  • @Jeremiahfuzz It's srand not strand!

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more