Generating random numbers with Mathematica

Click For Summary

Discussion Overview

The discussion revolves around generating 200 random numbers from an exponential distribution that sum to exactly one. Participants explore methods for achieving this while considering the implications of constraining the total sum on the randomness of the generated numbers.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant suggests using a loop to generate random numbers from an exponential distribution and checking their sum, but expresses difficulty in implementation.
  • Another participant raises concerns about the randomness of the numbers when constrained to sum to one, questioning the validity of the exponential distribution under these conditions.
  • A participant confirms that the total must be exactly one and discusses the challenges of choosing an appropriate lambda parameter for the exponential distribution, noting that a small lambda makes it difficult to generate the required numbers.
  • A proposed solution involves generating random numbers and then normalizing them to ensure they sum to one, while acknowledging that this may not fully preserve the exponential distribution characteristics.
  • Another participant emphasizes the importance of providing context for the problem to assess the appropriateness of the method being used and cautions that standardizing the sum may lead to misleading results.

Areas of Agreement / Disagreement

Participants express differing views on the implications of constraining the sum of the generated numbers, with some agreeing on the proposed normalization method while others caution against its potential drawbacks. The discussion remains unresolved regarding the best approach to maintain the properties of the exponential distribution while meeting the sum constraint.

Contextual Notes

Participants note the challenges associated with selecting an appropriate lambda parameter and the potential skewing of the distribution when the total is constrained. There is also mention of the need for speed in generating the numbers, which adds complexity to the problem.

maani
Messages
10
Reaction score
0
Hi everyone,
I am trying to generate 200 random numbers from an exponential distribution which have to add to one.
I guess I need a loop where in each step I generate a random number from the exponential distribution and check the sum, if it is less than one I add the number to a list and if not I generate another number. So at the and I have a list with 200 numbers which add to one.
The problem is I fail to implement this. Does anybody know an easier way to do this?

I will be grateful for any suggestions!
 
Physics news on Phys.org
Purists will rightfully say "but when you have constrained the total to be a sertain number the distribution is no longer random." Imagine you have chosen 190 of the 200 numbers, the total is almost exactly 1 and you are left with choosing 10 more numbers, all almost exactly zero. The distribution of the result will be skewed and not really exponential.

What is the lambda parameter you are using for your exponential distribution?
Does the total have to be EXACTLY 1.0?
Do you only need to do this one time and speed is not a concern or must this be done quickly?

Perhaps with that a line or two of code can be written to give you a solution.
 
Hi Bill,

thanks for your answer! To your questions:

2.The total of the numbers has to be exactly 1.0!I know strictly speaking these numbers are not random but I just don't know how to call them.

3. I have to do this more than once, so it has to be done relatively quickly.

1. As for the parameter λ I am not so sure what I should take. If I take λ too small (1-10) it will be very difficult, almost impossible to generate 200 random numbers with total 1. I choose exponential distribution because I need numbers from a wide range. But if I take λ too big (200) I cannot achieve that.
I also thought of changing λ in every step (see attached file). However it takes too long.

Do you have another idea?
 

Attachments

To have 200 numbers with an exponential distribution sum to 1 your lambda must be almost exactly 200.

To get the total to be exact I offer the following

v = RandomVariate[ExponentialDistribution[200], 200];
v = v/Total[v]

That seems to commit the least sin against an exponential distribution while still obtaining your total, but this isn't my field.

If an exponential distribution does not satisfy your requirements then I suggest thinking carefully about your problem and determining exactly what distribution models your problem correctly
 
Last edited:
Hey maani and welcome to the forums.

It might be helpful if you gave some context to your problem so that the readers can assess if the method you are using may be problematic.

Bill's idea to standardize the sum is a good one, but depending on what you are trying to do (as he has already pointed out), it may give misleading or simply incorrect analyses for your problem at hand.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 22 ·
Replies
22
Views
4K