Creating a probability controlled distribution

Hi, I am working on creating some code that can generate a number based on a probability. How can I accomplish something like this?

for example I want to generate a number that is between 1000 and 20000 where the number will be more likely to be closer to 1000 and exponentially less likely to be away from 1000.

So far I have tried doing approaches similar to:

  
local minint = 1000  
local maxint = 20000  
local iter = 4  
result = maxint  
  
for j = 1, iter do  
  
result = math.random(minint, result)  
  
end  

but the result is not very good because it depends on how high the values are and it does not really let me play around with the distribution curve to get the desired effect.

I’m over my head here, can anyone help?
[import]uid: 48775 topic_id: 8740 reply_id: 308740[/import]

I think you want something like a gaussian distribution, if I’m understanding your problem right. [import]uid: 8673 topic_id: 8740 reply_id: 31854[/import]

Yes something similar, but how could I implement a function in a way so that the numbers are generated with some kind of probability? [import]uid: 48775 topic_id: 8740 reply_id: 31856[/import]

http://www.taygeta.com/random/gaussian.html

This should give you a pretty clear idea on how to write a gaussian distribution function. [import]uid: 8673 topic_id: 8740 reply_id: 31881[/import]

cyberentity,
I have a high level idea:

  1. Consider you have a exponentially decaying curve y=e(x). Now you are dropping beans onto this graph.
  2. You may generate ranged random pairs (x1,y1). If you generate large enough amount of them, they should evenly distribute on a 2D rectangle spanning across the range on the graph.
  3. For each generated pair (x1,y1), you check if y1<=e(x1), i.e. to see if the generated random pair (x1,y1) lies on the area spanned below by y=e(x).
  4. Ignore those pairs which do not lie below the curve.
  5. Finally, if the amount of generated random pairs is large enough, consequently from the accepted pairs, you would get relatively more pairs of smaller x1, and relatively less pairs of large x1.
    Hope it helps.

– Advanced UI + Graph for Corona® | Website | Forum (https) | See: [import]uid: 11385 topic_id: 8740 reply_id: 32064[/import]