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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:20:04+00:00 2026-05-27T08:20:04+00:00

I wrote method that return random number between two given numbers. Here it’s header:

  • 0

I wrote method that return random number between two given numbers. Here it’s header:

int NumRange(int low,int high);

I want to check that method really return all the range between those two numbers,
so I wrote a test (here below), but in my opinion it’s too complicated. Maybe there is another way to check it, or I’m the best:)

TEST_F(RandomGeneratorTest, fill_all_the_range)
{
// In set - there is no duplicates
std::set<int> results;
int i;
for (i=0;i<1000;i++)
    results.insert(NumRange(0,9));
EXPECT_EQ(10, results.size());
}

Thank you, and sorry about my poor English.

EDIT:
After question, I bring here below another test that I wrote to complete the test scenario.

TEST_F(RandomGeneratorTest, only_in_the_range)

{
int i,result;
for (i=0;i<1000;i++)
{
    result = NumRange(0,9);
    EXPECT_TRUE((result<=9) && (result>=0));
}
}

EDIT 2:
Based on @cyborg answer (thank you), I made a histogram test (here below). But it’s very complicated, and test, in my opinion, should be very simple, so my question still alive. I search simple way to check.

TEST_F(RandomGeneratorTest, fill_all_of_the_histogram_range)
{
int results[10]= {0};
int i, approxRes;
for (i=0;i<100000000;i++)
    results[NumRange(0,9)]+=1;
for (i=0;i<10;i++)
{
    approxRes = results[i]/10000;
    EXPECT_TRUE((approxRes<=1001) && (approxRes>=999));
}
}
  • 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-27T08:20:05+00:00Added an answer on May 27, 2026 at 8:20 am

    You could test for a uniform distribution instead of for a complete coverage. To do this, compute a histogram and check that every bin gets more or less the expected amount.

    Edit:

    If you want more serious tests, see this answer: https://stackoverflow.com/a/1477505/907578

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

Sidebar

Related Questions

I have and old(ish) C# method I wrote that takes a number and converts
Here is the question: write a method that swaps two variables. These two variables
i have wrote a method that filters output with provided query and return it.
I just wrote a delegate method, that shall return an array, I've created inside
I wrote a method that extracts fields from an object like this: private static
I wrote a windows service in C# that does some functionality (a public method)
I wrote the following method that receives a list and updates the database based
I'm asked to create a method that returns the number of occurrences of a
Below are two simple Cython methods I wrote. In g_cython() method I used additional
I am using C# to write a method that returns the following information about

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.