问题描述
我想在python中生成多个随机数流.我正在编写一个用于模拟队列系统的程序,想要一个流作为到达时间,另一个流作为服务时间,等等.
I want to generate multiple streams of random numbers in python.I am writing a program for simulating queues system and want one stream for the inter-arrival time and another stream for the service time and so on.
numpy.random()
从全局流中生成随机数.
numpy.random()
generates random numbers from a global stream.
在matlab中,有称为RandStream的东西,它使我能够创建多个流.
In matlab there is something called RandStream which enables me to create multiple streams.
有什么方法可以在Python中创建类似RandStream的内容
Is there any way to create something like RandStream in Python
推荐答案
Numpy和内部随机生成器都有可实例化的类.
Both Numpy and the internal random generators have instantiatable classes.
仅用于random
:
import random
random_generator = random.Random()
random_generator.random()
#>>> 0.9493959884174072
对于Numpy:
import numpy
random_generator = numpy.random.RandomState()
random_generator.uniform(0, 1, 10)
#>>> array([ 0.98992857, 0.83503764, 0.00337241, 0.76597264, 0.61333436,
#>>> 0.0916262 , 0.52129459, 0.44857548, 0.86692693, 0.21150068])
这篇关于在python中生成多个独立的随机流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!