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

  • Home
  • SEARCH
  • 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 9062593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:46:33+00:00 2026-06-16T15:46:33+00:00

I need to generate a random number from the following data: 0-10 : 23%

  • 0

I need to generate a random number from the following data:

0-10 : 23%

10-80 : 50%

80-100 : 27%

How do I generate a random number from such information?

One way would be to fit a distribution but I have to do this for about hundred variables and I don’t want to fit 100 distributions. Any hints?

import random
a=[23, 73, 100]
b=[10, 80, 100]
rndval=awesomefunction(a,b)

Now, regarding awesomefunction(), I have absolutely no clue.

But, from what little I know, (and a very sloppy implementation)

temp_rand=random.uniform(0,100)
if(temp_rand<=23):
 rndval=random.uniform(0,10)
if(temp_rand<=73 && temp_rand>23):
 rndval=random.uniform(10,80)
if(temp_rand>73):
 rndval=random.uniform(80,100)

But IMHO, this is sloppy beyond measure.

  • 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-16T15:46:34+00:00Added an answer on June 16, 2026 at 3:46 pm

    You can have 2 random generators to achieve this. The first should generate a random double from 0 to 1.

    For this generator, you should check to see if the random number is from 0 to .22, .23 to .73, or .74 to 1. If the number falls within the first range, you just run another random number generator that generates a number from 0 to 10, and that’s your number. The same goes for the second and third ranges.

    Some high level pseudocode:

    double firstRandomNumber = generateRandomNumberFromZeroToOne();
    if (firstRandomNumber <= .22) {
        //generate random number from 0 to 10 and that's your number.
    } else if (firstRandomNumber <= .73) {
        //generate random number from 10 to 80 and that's your number.
    } else {
        //generate random number from 80 to 100 and that's your number.
    }
    

    A side note: Most languages already have random number generators that will generate a random number from 0 to 1 or an integer up to a specific range (0 to 10).

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

Sidebar

Related Questions

I need to generate a random port number between 2000-65000 from a shell script.
I need to generate a random number, but it needs to be selected from
I need to generate a random number from 1 to 5 which isn't already
A specific example I need to generate a random number between 0 and 2,
I need to generate an random array from a bigger array of int without
I need to generate a random number. But the twist is that the %
I'm trying to generate random numbers from a gaussian distribution. Python has the very
I need to generate quickly lots of random numbers from binomial distributions for dramatically
The following code generates random number from 1 to 10 $ran = rand(1,10); What
I am developing a program in which I need to generate a random number

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.