How to use 'random distribution' in Python

Every line of 'random distribution' 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
this disclaimer
4def random_distribution(total_requests, num_threads):
5 """
6 Return a list with a random distribution of
7 requests per thread. For returned list L and
8 thread index i, L[i] represents the number
9 of requests (randomly assigned) to thread i.
10 """
12 requests_per_thread = [0] * num_threads
14 while total_requests > 0:
15 for i in range(num_threads):
16 if random.choice( (True, False) ):
17 requests_per_thread[i] += 1
18 total_requests -= 1
19 return requests_per_thread

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

119def _random(a, size=None):
120 return stats.dirichlet.rvs(a, None if size == a.shape else size)

Related snippets