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.
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.
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.
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 !
You guys are good !