Link to home
Start Free TrialLog in
Avatar of choochim
choochim

asked on

using custom distribution in Oracle / PL/SQL

Looking for some urgent help with implementing a custom statistical distribution in Oracle 10g: The scenario goes like this: I want a function that returns a single value based on a table that looks like this:
Value   Freq%
*******  *********
A         5.3%
B         4.8 %
C         5.1 %
D         10.5 %
etc..etc..

When I call this function, I want it to return the value of A 5.3% of the time, the value of B 4.8% of the time and so on and so forth.

Is this possible using PL/SQL? if so could someone shed some light on how to approach this problem.

Much appreciated.
Avatar of johnsone
johnsone
Flag of United States of America image

The way I have done this in the past is to use a random number generator (DBMS_RANDOM for example) and generate a number between 0 and 1, then take your percentages and convert then to numbers (5.3% = .053) and check them in order to see where the number falls and return that value.
Avatar of choochim
choochim

ASKER

Johnsone:
thanks for the quick respone. One doubt though, what if I have multiple hits on a single random number value say - there are A,B,C as three possible hits for the same random number? Then what is the remedy?
ASKER CERTIFIED SOLUTION
Avatar of johnsone
johnsone
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks. After posting my initial response, I figured that out and modified to a cume percentage and that did the trick.

You guys are good !