Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old October 23rd, 2005, 01:30 AM
_jameshales _jameshales is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Location: Perth, Western Australia
Posts: 6 _jameshales User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 35 m 7 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old October 23rd, 2005, 04:15 AM
Learnable Learnable is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 1 Learnable User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 39 m 7 sec
Reputation Power: 0
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
{}

Reply With Quote
  #3  
Old October 23rd, 2005, 07:31 PM
_jameshales _jameshales is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Location: Perth, Western Australia
Posts: 6 _jameshales User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 35 m 7 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old October 23rd, 2005, 10:56 PM
Lux Perpetua Lux Perpetua is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: San Francisco Bay
Posts: 1,418 Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 47 m 27 sec
Reputation Power: 334
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.

Reply With Quote
  #5  
Old October 31st, 2005, 05:11 PM
_jameshales _jameshales is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Location: Perth, Western Australia
Posts: 6 _jameshales User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 35 m 7 sec
Reputation Power: 0
Thanks for your help. I'm about half-way there.

_jameshales

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > Weighted Random Theory


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway