rando
PURPOSE 
rando.m generates a random variable in {1, 2, ..., n} given a distribution vector.
SYNOPSIS 
function [index] = rando(p)
DESCRIPTION 
CROSS-REFERENCE INFORMATION 
This function calls:
This function is called by:
- simulate_chain simulate_chain.m simulates a Markov chain on {1, 2, ..., n} given an
- slot_machine slot_machine.m generates several outcomes of wealth while playing a hypothetical slot machine
SOURCE CODE 
0001
0002
0003 function [index] = rando(p)
0004 u = rand;
0005 i = 1;
0006 s = p(1);
0007
0008 while ((u > s) && (i < length(p))),
0009 i=i+1;
0010 s=s+p(i);
0011 end
0012
0013 index=i;
Generated on Mon 17-Mar-2008 10:33:42 by m2html © 2003