简体   繁体   English

如何在python中构建随机数生成器,以生成符合某些数据的数字

[英]How to build a random number generator in python that produces numbers in line with some data

Its a question from a problem set i have. 这是我提出的一个问题集的问题。 I need to devise a random number generator that produces request sizes that are in line with the data. 我需要设计一个随机数生成器,以生成与数据一致的请求大小。 And then devise another random number generator that produces interarrival times that are in line with the data. 然后设计另一个随机数生成器,该生成器生成与数据一致的到达时间。 After I done that I need to explain how I analysed the data to achieve this, and why I believe my random number generators are in line with the data. 完成之后,我需要解释如何分析数据以实现此目的,以及为什么我相信我的随机数生成器与数据一致。 I have analysed the data and have created a graph based on the sizes from the logs. 我已经分析了数据,并根据日志的大小创建了一个图表。

I build a random number generator in python that produces random numbers but they are not in line with the request sizes. 我在python中构建了一个随机数生成器,该生成器会生成随机数,但它们与请求大小不符。 so far i done this in python: 到目前为止,我在python中完成了此操作:

import random
import math
import cPickle

with open('Logs2.txt', 'w') as f_out:

    for i in range(17):
        t = ((-1.0 * (0.4)) * math.log(random.random()))
        f_out.write("{b}\n".format(b=t))

how am i supposed to create these random variables in line with my data. 我应该如何根据我的数据创建这些随机变量。 here is the data: 这是数据:

1
0.983606557
0.967213115
0.93442623
0.918032787
0.901639344
0.868852459
0.819672131
0.721311475
0.639344262
0.606557377
0.508196721
0.491803279
0.360655738
0.278688525
0.081967213
0.06557377
0.655737705

I have to create random variables that get close enough to these numbers, doesnt have to be in order, i later on sort them 我必须创建足够接近这些数字的随机变量,而不必按顺序排列,我稍后将它们排序

I don't understand precisely what you're asking, but it almost seems like you're looking to either model your data or fit it to a statistical distribution, or perhaps generate a set of data for each of your data points by using each point as the central tendency. 我不清楚您要问的是什么,但似乎您正在寻找要对数据建模或使其适合统计分布的方法,或者可能是通过使用每个数据点为每个数据点生成一组数据点是中心趋势。

In either case, you will probably want to use the NumPy module numpy.random . 无论哪种情况,您都可能要使用NumPy模块numpy.random This module includes a wide variety of statistical distribution functions with handy methods for created random variables with known central tendencies and deviation. 该模块包括各种统计分布函数,这些函数具有方便的方法来创建具有已知中心趋势和偏差的随机变量。 A good example is numpy.random.normal . numpy.random.normal是一个很好的例子。

SciPy is another must-have package for math/science intensive work, and it has (in my experience) more advanced (but less intuitive) statistics functions and classes. SciPy是另一个用于数学/科学密集型工作的必备软件包,据我的经验, SciPy具有更高级(但不太直观)的统计功能和类。 You might find scipy.stats useful. 您可能会发现scipy.stats有用。

Again, not sure exactly what you're asking. 同样,不确定您要问的是什么。 Please continue to comment if you need more help. 如果您需要更多帮助,请继续发表评论。

Typically pseduo -random number generators rely on the system clock to determine some semblance of "randomness", only so much as to create different numbers. 通常, pseduo-随机数生成器依靠系统时钟来确定某种“随机性”,仅以产生不同的数字为限。 This will not, however, create different patterns of different numbers. 但是,这不会创建不同数字的不同模式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM