我只是想问有没有办法把两个商品放在一起,例如,如果我从一个包含20个商品的大列表中生成4个随机的购物清单,它们都存储在我的全局(数组)中,如果我可以将它除以4,然后随机地把我在c#中知道的4个较小的清单放在一起,我可以使用' random‘库,在Mumps objectscript中有类似的东西吗?
发布于 2013-09-09 01:45:35
$RANDOM(n) (或$R)会有帮助吗?它生成一个介于0和n之间的随机数。
发布于 2013-09-10 06:08:39
RLIST
N ITMS,I,FLG,R,ND,RES
F I=1:1:20 S ITMS(I)="Item "_$E(I+100,2,3) ; generate a list of items
S ND="RES" K @ND
;
F I=1:1:20 D ; iterate through the list of items
.S FLG="" F D Q:FLG ; randomly select a target list
..S R=$R(5)+1 ; this will yield (0-4)+1 -> 1-5
..I $L($G(@ND@(R)),",")<4 D S FLG=1 ; has the target list less then 5 items?
...S @ND@(R)=$G(@ND@(R))_$S($G(@ND@(R))="":"",1:",")_ITMS(I) ; if so, add one
;
F I=1:1:5 U 0 W "List "_I_": "_@ND@(I),! ; print the target lists
Q

https://stackoverflow.com/questions/18685508
复制相似问题