mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 07:38:21 +00:00
Implement llListRandomize for the calculator
This commit is contained in:
parent
02b37d6dad
commit
be479771aa
1 changed files with 25 additions and 2 deletions
|
@ -1486,8 +1486,31 @@ def llListInsertList(lst, elems, pos):
|
|||
# Unlike llInsertString, this function does support negative indices.
|
||||
return lst[:pos] + elems + lst[pos:]
|
||||
|
||||
# not implemented as it does not give the same output for the same input
|
||||
#def llListRandomize(x):
|
||||
def llListRandomize(lst, stride):
|
||||
if lslcommon.IsCalc:
|
||||
lst = fl(lst)
|
||||
stride = fi(stride)
|
||||
L = len(lst)
|
||||
if stride <= 0:
|
||||
stride = 1
|
||||
if L % stride == 0:
|
||||
# valid stride
|
||||
L //= stride # length in records
|
||||
import random
|
||||
for i in range(L - 1):
|
||||
# choose which record to swap it with
|
||||
rnd = random.randint(i, L - 1)
|
||||
# swap each record
|
||||
lst[i*stride:(i+1)*stride], lst[rnd*stride:(rnd+1)*stride] = \
|
||||
lst[rnd*stride:(rnd+1)*stride], lst[i*stride:(i+1)*stride]
|
||||
#else:
|
||||
# # if the stride isn't valid, don't modify the list
|
||||
# pass
|
||||
|
||||
return lst
|
||||
|
||||
# Can't give a concrete value
|
||||
raise ELSLCantCompute
|
||||
|
||||
def llListReplaceList(lst, elems, start, end):
|
||||
lst = fl(lst)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue