Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

random ordered slice of an array

import random as rd
import numpy as np

mylist = list(np.linspace(0,50,50))
sliceSize = 3 # +1 below because python start counting frfom zero
result = mylist[rd.randrange(len(mylist)-sliceSize+1):][:sliceSize]
print(result)
Output: [6.122448979591837, 7.142857142857143, 8.16326530612245]
 
PREVIOUS NEXT
Tagged: #random #ordered #slice #array
ADD COMMENT
Topic
Name
9+8 =