Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8329199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:41:52+00:00 2026-06-09T01:41:52+00:00

This is probably a stupid question, but I’m really struggling with this concept. I’m

  • 0

This is probably a stupid question, but I’m really struggling with this concept. I’m going through a tutorial explaining about arrays and the rand() function. I have two problems.

The first is, obviously to simulate one dice we need to randomly generate a number from 1-6. The book suggests this:

int       RollOne( void ) {
    return (rand() % 6) + 1;
}

Right, well rand() can generate any number from 0-32767. We then find the remainder of this number when it’s divided by 6, then add 1. E.g. 3245 is randomly generated. We divide it by 6, giving 540.8333 and take the remainder. 8.333 (truncated to 8 I believe) and then add 1. Unless I’m going mad, that makes 9, which is not between 1-6. The program runs fine however and I just can’t understand how we get a number from 1-6 using that code! Any help would be greatly appreciated.

The second problem I have isn’t really as major, but is relevant. The book left out what this bit of code means:

srand( clock() );

All that is mentioned is that srand() initialises a random number generator using the seed provided by clock(). Right, now can we actually input anything into clock(), if so what is its effect? Just a little explanation of what srand( clock() ) does would be perfect.

Sorry for the long post, I hope you don’t mind the wall’o’text. Any help would be really appreciated.

Thanks,
Mike

ANSWERED
Thank you everyone: I realise what I was doing. As shown by you guys, the % operator doesn’t divide, it just finds the difference between the highest multiple and the operand. Got it! I was under the impression that the remainder meant the decimal. I.e. If 7/2 = 3.5 then the remainder is 0.5. Now that I’ve written it out, I see how stupid I’ve been. Glad my A-level maths counts for something…..
Thanks again!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:41:54+00:00Added an answer on June 9, 2026 at 1:41 am

    3245 is randomly generated. We divide it by 6, giving 540.8333 and
    take the remainder.

    You are confused between integer truncation and remainders. When you divide 3245 by 6 using integer math the remainder is 5 (or 0.83333 * 6 = 5).

    Another way to see this is 540 * 6 = 3240, which leaves a remainder of 5.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok. This is probably a really stupid question, but I'm going to ask it
This is probably a stupid question. I don't know anything about Web Service but
This probably sounds like a stupid question, but I'm going to give it a
This is probably a really stupid question but I can't figure this out. I
This is probably a really stupid question, but how do I turn on these
This is probably a really stupid MSBuild question but if I have <ItemGroup> <Dll
This is probably a really stupid newbie-sounding question to you developer type people, but
This is probably going to end up as a stupid question, but countless research
this is probably a really stupid question, but I am big R newbie and.
this is probably a stupid question but I can't seem to find the answer.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.