|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Weighted Random Theory
Does anyone know of any links to the theories behind generating weighted numbers? Particularly I want to be able to generate a random floating point number between 0 and 1. But I want it so that the likely hood of each number between 0 and 1 appearing, can be predicted with a simple equation, i.e. that produces a parabola, so that maybe the numbers near the middle are more likely to appear, or the numbers on one side, etc.
It's just that I've found plenty on weighted random choices, but those are usually finite number of choices. I'm using this for a game where each player has a "luck" value. Basically I want this parabola of probability to move from one side of the spectrum, i.e. 0, to the other, so that as your luck increases, it's more likely that it'll produce a 1. Up until now I've simply been taking a random number, dividing it by the luck value, and taking that from one (so it goes closer to one as luck increases), but that completely takes away the possibility of a lower number appearing, rather than simply making it less likely. Thanks in advance for any help. |
|
#2
|
|||
|
|||
|
Probability
Why can't you use the luck value as a probability which increases or decreases according to your function, and then:
float n = Random(); if(n < luck) {} else {} |
|
#3
|
|||
|
|||
|
I wanted a number to come out of it. It's for an RPG style game, and the luck values will be used in some situations for decisions, but mostly for modifying values like hit damage and such, with a random degree of error - i.e. so that the final damage dealt could be 75% - 125% of the value that I had before. The random number, multiplied by 50% of the value, would be subtracted from the value, and a 25% of the value added back on, so that if the random number is 1, the value will equate to 125%, and if it's 0, the value will equate to 75%. The luck value should make one end of the spectrum more probable, so that a higher luck value would turn up more values closer to 1.
If we were to graph the frequencies of the random numbers from 1 to 0, it should form some sort of bump in the middle. As the luck value increases, that bump should move closer to the 1, so that 1's appear more often than before. I found something about Gaussian random values that I think will work however I'm trying to investigate exactly how they work. _jameshales |
|
#4
|
|||
|
|||
|
So you want to define a probability density function f on the interval [0,1] that looks something like a parabola, and you want to generate random numbers according to this distribution? Here's one way to do it:
1) Find the indefinite integral from 0 to x of f, and call this function F. 2) Find the inverse of F. Call this function G. 3) Now you can simply generate a uniform random number x between 0 and 1 and return G(x) as your weighted random number. For this to work, your density function f must of course be a valid probability distribution, meaning A) It is never negative, B) Its integral from 0 to 1 is equal to 1. (If your f satisfies property A, then you can make it satisfy property B by scaling it.) Of the three steps above, (1) and (2) could be more or less tricky depending on your density function. A parabola is very easy to integrate, but its indefinite integral is a cubic function, and although cubics can be inverted, the formula is quite complicated. There are ways to do it without finding the explicit inverse formula, though. |
|
#5
|
|||
|
|||
|
Thanks for your help. I'm about half-way there.
_jameshales |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Software Design > Weighted Random Theory |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|