Here you can find the source of multSample(Random rng, double[] vals, double normsum)
Parameter | Description |
---|---|
rng | a parameter |
vals | a parameter |
normsum | a parameter |
public static int multSample(Random rng, double[] vals, double normsum)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /**// w w w . ja va 2 s .c o m * Draw a multinomial sample from (un-normalized) vals * * @param rng * @param vals * @param normsum * @return */ public static int multSample(Random rng, double[] vals, double normsum) { double rval = rng.nextDouble() * normsum; double cumsum = 0; int j = 0; while (cumsum < rval || j == 0) { cumsum += vals[j]; j++; } return j - 1; } }