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 9311303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:19:48+00:00 2026-06-19T01:19:48+00:00

So, I am using the modulus and a rand as part of a function

  • 0

So, I am using the modulus and a rand as part of a function I am writing. Now, I understand that:

rand() % 6 + 1; gives me a random number between one and six in this situation. However, I also know that

rand(); gives me a random value from 0 – 32767 and srand; changes the sequence

but I thought…

% = Whatever the remainder of a is after a / b.

… So, if you were to break rand() % 6 + 1; up, what would it look like?

I need to make sense of this for my own good because I look at rand() % 6 + 1; like this:

some random number / 6 = remainder left over from the random. Then add the one.

So, my question is two fold:

1 – how does rand() get restricted to just 1 – 5 all of a sudden instead of the spectrum of numbers from 0 – 32767?

2 – Any of those numbers (1-5) divided by 6 gives you a fractional number, not a whole one and I thought modulus only works with whole numbers. What info am I missing here?

As you can see I am confused about this. Help is always appreciated 🙂

  • 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-19T01:19:49+00:00Added an answer on June 19, 2026 at 1:19 am

    rand()%6 gives the reminder of the random number generated when divided by 6

    For example if rand() generates a number 100, then the result of 100%6 is the reminder obtained when 100 is divided by 6, which is 4. So whatever the number is generated from the function rand(), when %6 is done, the output will be within 0-5(the reminder when divided by 6).

    “how does rand() get restricted to just 1 – 5 all of a sudden instead of the spectrum of numbers from 0 – 32767?”

    rand() does not get restricted to “0-5”, it still outputs the numbers from 0 – 32767(or whatever don’t know the max limit). But when we do rand()%6, then the output will be in the range 0-5

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

Sidebar

Related Questions

I know that you can get the digits of a number using modulus and
I'm currently using a mediator that sits in-between all my modules and allows them
I recently ran into an issue that could easily be solved using modulus division,
Good morning, I have to create a random number from a given 256HASH using
I'm trying to create a modulus function within haskell using primtive recursive functions. I
How do you deal with Java's weird behaviour with the modulus operator when using
MVC3 VB.NET application using Itextsharp. I have a section of code that generates a
I'm writing a program using bitarray for example: bytePerInt = sys.getsizeof(1) class BitMap(object): def
I'm trying to write a very simple program in C++ that finds the modulus
I want to create a grid of tiles using position:absolute that consists of 5

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.