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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:43:56+00:00 2026-05-27T16:43:56+00:00

I have a function getrand100() which returns a random number from 0-100 Write a

  • 0

I have a function getrand100() which returns a random number from 0-100

Write a code snippet to print numbers 1-200 in a random order with none of them repeating. You may call getrand100() any number of time to get random number from 1 to 100.

Please help how to do this?

  • 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-27T16:43:56+00:00Added an answer on May 27, 2026 at 4:43 pm

    Create an array of numbers from 0 to 200. Then, use the Fisher-Yates Shuffle to shuffle them.

    Since your getrand100 function only gives numbers from 0 to 100, write something like this:

    int rnd = getrand100();
    int scale = getrand100();
    if (scale >= 50)
        rnd += 100;
    

    That will give you random numbers from 0 to 200.

    Actually, it’s a little more complicated than that because the range of random numbers changes. That is, at first you want to generate a random number from 0 to 200. The next time, from 0 to 199, then 198, 197, etc. So you need a way to scale your random numbers. Something like the following will get you reasonably close to uniform distribution:

    int rnd = getrand100();
    double frnd = rnd / 100.0;
    int realRnd = round(frnd * range);
    

    This assumes you have a rounding function. range is the top of your range. So the first call, range is 200, then 199, etc.

    That won’t give you perfect uniform distribution, since you’ll only be working with two significant digits, but it will give an acceptable result for a classroom assignment.

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

Sidebar

Related Questions

For getting the random numbers I have a function getrand100() which returns a random
In my Java code I have function that gets file from the client in
I have function: char *zap(char *ar) { char pie[100] = INSERT INTO test (nazwa,
i have function which return list as given below. List<User> lstUsers = SearchUsers(searchText); which
I have function that have been colled in stored procedure. The function returns a
i have function, which has to accept two types of data - Observable collection
I have function which takes in an parameter of a class called Triple, and
I have this code in my controller (admin): function save(){ $model = $this->getModel('mymodel'); if
i want to have function like delete file from database by using link instead
I have simple from written on C/gtk+ and i have function in this appliction.

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.