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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:27:07+00:00 2026-05-22T01:27:07+00:00

rand(n) returns a number between 0 and n . Will rand work as expected,

  • 0

rand(n) returns a number between 0 and n. Will rand work as expected, with regard to “randomness”, for all arguments up to the integer limit on my platform?

  • 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-05-22T01:27:08+00:00Added an answer on May 22, 2026 at 1:27 am

    This is going to depend on your randbits value:

    rand calls your system’s random number generator (or whichever one was
    compiled into your copy of Perl). For this discussion, I’ll call that
    generator RAND to distinguish it from rand, Perl’s function. RAND produces
    an integer from 0 to 2**randbits – 1, inclusive, where randbits is a small
    integer. To see what it is in your perl, use the command ‘perl
    -V:randbits’. Common values are 15, 16, or 31.

    When you call rand with an argument arg, perl takes that value as an
    integer and calculates this value.

                            arg * RAND
              rand(arg) = ---------------
                            2**randbits
    

    This value will always fall in the range required.

              0  <=  rand(arg)  < arg
    

    But as arg becomes large in comparison to 2**randbits, things become
    problematic. Let’s imagine a machine where randbits = 15, so RAND ranges
    from 0..32767. That is, whenever we call RAND, we get one of 32768
    possible values. Therefore, when we call rand(arg), we get one of 32768
    possible values.

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

Sidebar

Related Questions

The problem is not about randomness itself (we have rand), but in cryptographically secure
Here is a function in PHP that generates a random number between 1 and
Is there a way of generating a random number in ruby between, say, 1
I am having trouble getting rand() to work in C++. rand() normally gives me
I'm trying to figure out how to map a number between 1 and 1000
I wrote this C code below, when I loop, it returns a random number.
Is there any Go function which returns true pseudo random number in every run?
clc clear all ii=1; S =cell(size(30,1)); % cell size. for ii=1:1:3 rand_id= rand(1,1) *3;
int totalRecs = getTotalRecs(); // returns '13' int MAX_RECS_PER_LOOKUP = 10; Random rand =
Whenever I use the rand function in C++: #include<iostream> #include<time.h> #include<stdlib.h> using namespace std;

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.