Subversion Repositories wimsdev

Rev

Rev 4161 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
20 reyssat 1
!if $wims_read_parm!=slib_header
2
 !goto proc
3
!endif
4
slib_title=Generation of random numbers with a discrete law
5
slib_parms=3\
6
  1,m\
7
  ,[p1,p2,..pj]\
8
  ,[v1,v2,..vj]
9
slib_author=S. Lemaire and Bernadette Perrin-Riou
10
slib_out=random  data of m numbers following the law [p_1,p_2,..p_j]\
11
on the values [v_1,v_2,..v_j] (p_i are positive reals of sum 1)
12
 
13
 
14
slib_comment= P(X=v_i)=p_i
15
 
16
slib_example= 5,[0.5,0.5],[3,7]\
17
5,[1/3,1/3,1/3],[pile,face,tranche]
18
 
19
!exit
20
 
21
:proc
22
 
23
!distribute item $wims_read_parm into slib_m, slib_p,slib_v
24
 
25
slib_out=$empty
26
!default slib_m=1
27
slib_p=!declosing $slib_p
28
slib_v=!declosing $slib_v
29
slib_t=!itemcnt $slib_p
30
slib_s=!item 1 of $slib_p
31
slib_q=$slib_s
32
 
33
!for slib_i=2 to $[$slib_t -1]
34
  slib_a = !item $slib_i of $slib_p
35
  slib_s=$[$slib_s + $slib_a]
36
  slib_q=!append item $slib_s to $slib_q
37
!next slib_i
38
slib_q=!append item 1 to $slib_q
39
slib_U=!random 0,1 repeat $slib_m
40
 
41
!for slib_i=1 to $slib_m
42
 slib_pr=!item $slib_i of $slib_U
43
 slib_j=1
44
:debut
45
 slib_a=!item $slib_j  of $slib_q
46
 !if $slib_pr >= $slib_a
47
  !advance slib_j
48
  !goto debut
49
 !endif
50
 
51
slib_r= !item $slib_j of $slib_v
52
slib_out=!append item $slib_r to $slib_out
53
!next slib_i
54
 
55
slib_out =!trim $slib_out