阡喏
如何生成不重复随机数
具体情况:
有36个目标,从中可以随机抽取1~36个(也就是每次生成的随机数个数可以自定义),但抽取不重复

FireworkPolymer
https://www.mcbbs.net/thread-1285969-1-1.html
不知道能不能帮到你

幻心飞小骥
建议一个可能可行的方案:
summon一个实体
取其uuid并存入计分板
对计分板的那个数取模(%36)
只要那个被召唤的实体不趋势,应该就不可能有重复;就算实体趋势,抽到相同uuid的可能性也是极小的

cvbyisme
不是有计分板吗,用计分板自带的随机分数指令,每随机一次就记录一次数字。比如随机到了26,就把26记录下来,由于随机分数(范围可控)可能重复,那么在计分板再次随机到26时就重新生成随机数,做到不重复

阡喏
cvbyisme 发表于 2023-7-17 21:08
不是有计分板吗,用计分板自带的随机分数指令,每随机一次就记录一次数字。比如随机到了26,就把26记录下来 ...

这样会很麻烦,而且判定起来不容易,计算量也大

晴路卡
简单的洗牌:
generic:list/shuffle/do
  1. # 用法:
  2. # 先执行 data modify storage generic:main ListInput0 set from <待洗牌的列表>
  3. # 再执行 function generic:list/shuffle/do
  4. # 输出会放在generic:main ListOutput0当中

  5. execute store result score #list.temp.0 loy.value run data get storage generic:main ListInput0
  6. execute if score #list.temp.0 loy.value matches 1.. positioned 0.0 1.0 0.0 run function generic:list/shuffle/loop

  7. data modify storage generic:main ListOutput0 set value []
  8. execute positioned 0.0 1.0 0.0 as @e[type=marker,tag=entity.temp,distance=...1,sort=random] run function generic:list/shuffle/result
复制代码
generic:list/shuffle/loop
  1. execute summon minecraft:marker run function generic:list/shuffle/zzz/0
  2. scoreboard players remove #list.temp.0 loy.value 1
  3. execute if score #list.temp.0 loy.value matches 1.. run function generic:list/shuffle/loop
复制代码
generic:list/shuffle/zzz/0
  1. data modify entity @s data.Element set from storage generic:main ListInput0[0]
  2. data remove storage generic:main ListInput0[0]

  3. tag @s add entity.temp
  4. tag @s add loy.obj
复制代码
generic:list/shuffle/result
  1. data modify storage generic:main ListOutput0 append from entity @s data.Element
  2. kill @s
复制代码





第一页 上一页 下一页 最后一页