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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:43:21+00:00 2026-05-24T23:43:21+00:00

In somehow I need an random function that can generate highly uniform numbers, such

  • 0

In somehow I need an random function that can generate highly uniform numbers, such as, when I say [5,5], and I run this function for 10 times, I would like to have 5 number that are less than 0.5 and other 5 numbers are greater than 0.5.

Every run should be separated, like:

for i in range(0,10):
   rnd=random_function([6,3,1])
   print rnd

After having run this function for ten times, then I have 6 numbers are less than 0.6, 3 numbers are between 0.6 and 0.9, and 1 number are between 0.9 to 1.

Does anyone know how can I do that? Because the random function inside python is not that uniform…. Thanks!!

  • 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-24T23:43:21+00:00Added an answer on May 24, 2026 at 11:43 pm

    What you are asking for is not random; indeed, it is fairly structured. The point of random data is that it isn’t structured: you can’t say anything about what the values will be, only what they will be on average.

    You can still do what you want, though: just specify the ranges you want your numbers to fall into.

    >>> def random_function(*args):
    ...     n = sum(args)
    ...     bottom = 0
    ...     for m in args:
    ...             for _ in range(m):
    ...                     yield random.uniform(bottom, bottom + m/n)
    ...             bottom += m/n
    ...
    >>> list(random_function(6,3,1))
    [0.1849778317803791, 0.2779140519434712, 0.08380168147928498, 0.5477412922676888
    , 0.5158697440011519, 0.5535466918038039, 0.8046993690361345, 0.714614514522802,
     0.7102988180048052, 0.9608096335125095]
    >>> list(random_function(6,3,1))
    [0.29313403848522546, 0.5543469551407342, 0.14208842652528347, 0.344464024804118
    7, 0.3168266508239002, 0.5956620829410604, 0.673021479097414, 0.7141779120687652
    , 0.7783099010964684, 0.9103924993423906]
    

    Explanation:

    Given (6,3,1), work out their sum (10). We want six numbers between 0 and 6/10, three numbers between 6/10 and 6/10 + 3/10, and one number between 6/10 + 3/10 and 6/10 + 3/10 + 1/10. We can generate these by calling

    random.uniform(0, 6/10) six times,
    random.uniform(6/10, 9/10) three times, and
    random.uniform(9/10, 1) once.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to generate multiple random values under SQL Server 2005 and somehow this
For an iPhone app that submits images to a server I need somehow to
Is this possible? Code: $('#goRightBtn').click(function() { Random code here }; I have a button,
I'm in need of a C++ (pseudo, i don't care) random number generator that
I finally determined that this function is responsible for the majority of my bottleneck
On the client machine I need to be able to somehow detect which sites
PriorityBlockingQueue is unbounded, but I need to bound it somehow. What is the best
Somehow I had the impression that ASP.Net differentiates URLs based on the number of
I somehow need to trim() the innerHTML of my content... so I have something
I'm building a game project where there are simple container objects that can have

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.