#include <stdlib.h>
int
genProbDiscr
(
double
*
prob
,
int
nVal
){
int
i
=
0
,
r
;
r
=
rand
();
while
(
prob
[
i
]<(
double
)
r
/
RAND_MAX
)
i
++;
return
i
;
}