mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
add shuffle & choice
Update builtins.h
This commit is contained in:
parent
2f1effb3e4
commit
d03d168b8c
@ -208,10 +208,21 @@ class Random:
|
||||
if a > b:
|
||||
a, b = b, a
|
||||
return self.random() * (b - a) + a
|
||||
|
||||
def shuffle(self, L):
|
||||
for i in range(len(L)):
|
||||
j = self.randint(i, len(L) - 1)
|
||||
L[i], L[j] = L[j], L[i]
|
||||
|
||||
def choice(self, L):
|
||||
return L[self.randint(0, len(L) - 1)]
|
||||
|
||||
_inst = Random()
|
||||
seed = _inst.seed
|
||||
random = _inst.random
|
||||
randint = _inst.randint
|
||||
uniform = _inst.uniform
|
||||
shuffle = _inst.shuffle
|
||||
choice = _inst.choice
|
||||
|
||||
)";
|
Loading…
x
Reference in New Issue
Block a user