Dice roll results - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: Dice roll results (/thread-15051.html) Dice roll results - Tonig00 - 05-24-2020 04:05 PM Hello I am blocked. Any help welcome. I want to put in a matrix the possible variations of throwing t dice of c sides. For 3 dice of 3 sides will be something like (3^3 lines): [[111][112][113][121][122][123][131][132][133][211]….[333]] My initial aproach is: EXPORT TossDice(toss,sides) BEGIN LOCAL i,j,k,f,c,p,r; f:=sides^toss; c:= toss; MAKEMAT(f,c)▶r; p:=1; FOR i FROM 1 TO f DO FOR j FROM c+1-p DOWNTO 1 DO FOR k FROM 1 TO c DO r[i+k-1,j]:=k; END; END; END; END; It is a function similar to rolldie() in R software (prob package). It does not work and it seems to me that I would have to nest a lot of "for" loops to get it. I do not think is the way to get it. May be in the forum it has appeared before, if so tell me where. Thanks very much for your help Toni RE: Dice roll results - victorvbc - 05-24-2020 06:02 PM So you want a deterministic matrix with all the possibilities, not a random distribution, is that it? RE: Dice roll results - ijabbott - 05-24-2020 09:15 PM You should be able to do it with a couple of loops: EXPORT TossDice(toss,sides) BEGIN LOCAL i,j,f,p,r; f := sides^toss; MAKEMAT(f,toss)▶r; FOR i FROM 1 to f DO p := i-1; FOR j FROM 1 to toss DO r[i,j] := 1 + p MOD sides; p := IP(p / sides); END; END; END; I haven't tested it. RE: Dice roll results - Carlos295pz - 05-24-2020 11:28 PM Code: ```EXPORT TossDice(toss,sides) BEGIN   MAKEMAT(IP((I-1)/(sides^(toss-J))) MOD sides+1,sides^toss,toss); END;``` RE: Dice roll results - Tonig00 - 05-25-2020 06:28 PM Thanks very very much to all. Beautiful, simple, just much better than what I have finally done with a big mess: EXPORT RollDi(toss,dice) BEGIN LOCAL v,v1,j,k,d,f; LOCAL t,p,p1,r,r1,l; d:=dice; v:=MAKEMAT(J+K,1,d); v1:=MAKEMAT(0,1,d); t:=toss; f:=d^t; r:=MAKEMAT(0,t,f); r1:=MAKEMAT(0,1,f); p:=1; FOR k FROM 1 TO t DO //loop de t columnas WHILE p