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

Question:

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. so far i done this in 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

Asked By: Adam Adamou

||

Answers:

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. 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.

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. You might find scipy.stats useful.

Again, not sure exactly what you’re asking. Please continue to comment if you need more help.

Answered By: mdscruggs

Typically pseduo-random number generators rely on the system clock to determine some semblance of “randomness”, only so much as to create different numbers. This will not, however, create different patterns of different numbers.

Answered By: yurisich
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.