10 examples of 'random.sample python' in Python

Every line of 'random.sample python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
48def sample():
49 anchor_start = random.randint(2)
50 anchor_end = not anchor_start and random.randint(2)
51
52 start_len = random.randint(1)
53 match_len = random.randint(2) + 1
54 rep_len = random.randint(3)
55 end_len = random.randint(1)
56
57 start = "^" if anchor_start else ""
58 start += sample_block(start_len)
59
60 match = sample_block(match_len)
61 replace = sample_replace(rep_len)
62
63 end = sample_block(end_len)
64 if anchor_end:
65 end += "$"
66
67 before = "(%s)(%s)(%s)" % (start, match, end)
68 after = "\\1%s\\3" % replace
69
70 return before, after
9def safe_random_sample(data: Sequence[T], size: int) -> Sequence[T]:
10 if size < len(data):
11 return random.sample(data, size)
12 return data
26def space_sample(value, size, rand_generator):
27 size = None if size == 1 else size
28 rand_generator = rand_generator or np.random
29 try:
30 return rand_generator.choice(value, size=size)
31 except ValueError:
32 idx = rand_generator.randint(0, len(value))
33 return value[idx]
28def sample(self, sample):
29 ''' '''
30
31 if(self.counter < self.maxSamples):
32 self.samples.append(sample)
33 else:
34 index = randint(0, self.counter)
35 if(index < self.maxSamples):
36 self.samples[index] = sample
37
38 self.counter = self.counter + 1
28def _sample(space, n):
29 return np.array([space.sample() for _ in range(n)])
197def sample(self, n):
198 b_idx = np.random.randint(0, len(self.x), n)
199 bx, by = self.x[b_idx], self.y[b_idx]
200 return bx, by
27def sampler(rng):
28 return {"max_depth": rng.randint(1, 100), "n_estimators": rng.randint(1, 300)}
69def sample_batch(X, batch_size):
70
71 idx = np.random.choice(X.shape[0], batch_size, replace=False)
72 return X[idx]
273def choice(self, seq):
274 """Choose a random element from a non-empty sequence."""
275 return seq[int(self.random() * len(seq))] # raises IndexError if seq is empty
14def random(size):
15 return rand(*size)

Related snippets