Archived
1
0
Fork 0

Add ~random shuffle

This commit is contained in:
Dianliang233 2023-05-01 12:18:03 +08:00
parent 4a9d701ce0
commit 42d5a46efc
3 changed files with 23 additions and 10 deletions

View file

@ -22,6 +22,17 @@ async def _(msg: Bot.MessageSession):
await msg.finish(secrets.choice(choices))
@r.handle('shuffle ... {{random.help.shuffle}}', )
async def _(msg: Bot.MessageSession):
cards: list = msg.parsed_msg['...']
x = cards.copy()
for i in reversed(range(1, len(x))):
# pick an element in x[:i+1] with which to exchange x[i]
j = secrets.randbelow(i + 1)
x[i], x[j] = x[j], x[i]
await msg.finish(', '.join(x))
@r.handle('uuid {{random.help.uuid}}', )
async def _(msg: Bot.MessageSession):
await msg.finish(str(uuid.uuid4()))

View file

@ -1,6 +1,7 @@
{
"random.help.number": "Generate a random integer within a given range.",
"random.help.choice": "Select an element from a given set.",
"random.help.uuid": "Generate random UUID (v4).",
"random.help.desc": "Random number generator (cryptographically secure)"
{
"random.help.number": "Generate a random integer within a given range.",
"random.help.choice": "Select an element from a given set.",
"random.help.shuffle": "Shuffle the order of a given set.",
"random.help.uuid": "Generate random UUID (v4).",
"random.help.desc": "Random number generator (cryptographically secure)"
}

View file

@ -1,6 +1,7 @@
{
"random.help.number": "生成区间内的随机整数。",
"random.help.choice": "从集合中选择元素。",
"random.help.uuid": "生成随机 UUIDv4。",
"random.help.desc": "随机数生成器(密码学安全)"
{
"random.help.number": "生成区间内的随机整数。",
"random.help.choice": "从集合中选择元素。",
"random.help.shuffle": "打乱集合的顺序。",
"random.help.uuid": "生成随机 UUIDv4。",
"random.help.desc": "随机数生成器(密码学安全)"
}