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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:08:46+00:00 2026-06-14T19:08:46+00:00

I’m trying to simulate a continuous randomly generated number distribution in Python and find

  • 0

I’m trying to simulate a continuous randomly generated number distribution in Python and find the combined numbers (where y=x1+x2) fall within p(0.9

n = 10000
x11 = [random.random() for i in range(n)]
x12 = [random.random() for i in range(n)]
x21 = [-0.5*(log(1-random.random())) for i in range(n)]
x22 = [-0.5*(log(1-random.random())) for i in range(n)]
x31 = [random.random() for i in range(n)]
x32 = [random.uniform(0,2) for i in range(n)]
x41 = [0.25 if random.random() < 0.8 else 1.5 for r in range(n)]
x42 = [0.25 if random.random() < 0.8 else 1.5 for r in range(n)]

x11 through x42 are pairs of cases that I’m trying to get the probability that they’ll fall between 0.9 and 1.8 where the pairs of lists generated are combined and then operated on. So x11 and x12 are combined and then expected value, variance, and the 0.9 to 1.8 p(x) is found.

def test():
  x1,x2,c = 0.0,0.0,0.0
  for i in range(10000):
    if random.random()< 0.8:
      x1 += 0.25
    else:
      x2 += 1.5
    y = x1 + x2
    if y>0.9 and y<=1.8:
      c = c + 1
  return x1,x2,c

print "test: ",test()

def sim(a,b):
  #pyab1 = sum([a for a in a if a>0.9 and a<=1.8])/10000
  #pyab2 = sum([b for b in b if b>0.9 and b<=1.8])/10000
  #print "*****",float(pyab1+pyab2)
  #print a+b
  #array1 = [[a],[b]]
  array1 = a+b
  #array1.extend(a)
  #array1.extend(b)
  #c = 0
  #for y in array1:
    #if y>0.9 and y<=1.8:
      #c = c + 1
  pyab = sum([y for y in array1 if y>0.9 and y<=1.8])/10000
  print("P(a < x <= b) : {0:8.4f}".format(pyab))

I’m only counting the probability P(0.9<%Y<=1.8) so the count has to fall within those values. The 1-random.random() was only for that case, when I tried using that for all the cases they still came up with the wrong values. Here’s the theoretical outcomes and you can see how it’s different:

y~u(0,1)
= 0.575

y~exp(2)
= 0.3371

x1~u(0,1)
x2~u(0,2)

P(y=0.25)=0.8
P(y=1.5)=0.2
= 0.2

Here’s the output followed by the values it’s supposed to give, but this shows how far off the results are.

case 1: P(a < x <= b) : 0.7169 #should be 0.575 
case 2: P(a < x <= b) : 0.4282 #should be 0.3371 
case 3: P(a < x <= b) : 0.5966 #should be 0.4413 
case 4: P(a < x <= b) : 0.5595 #should be 0.2 

I’m very new to Python so please be patient if my question seems to have an obvious solution that I missed.

  • 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-14T19:08:47+00:00Added an answer on June 14, 2026 at 7:08 pm

    most probably you’d better replace

    pyab = sum([y for y in array1 if y>0.9 and y<=1.8])/10000
    

    with

    pyab = len([y for y in array1 if y>0.9 and y<=1.8])/len(array1)
    

    since you need the probabilities, but not the sum of the actual values. also, the len(array1) most probably is not 10000, but the combined length of two arrays.

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I have an array which has BIG numbers and small numbers in it. I

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.