I intend to make a simulation of real-data ie produce data at irregular time intervals. Below is some prototype code I wrote in python to simulate irregular time(not data), but the results are that my loop runs too fast such that each "time"(dat) produced is produced at the same time stamp. On top of this code, I intend to feed data set and pass in the data at these irregular time stamps.
import time,random
Tadd=0.1
start=time.time()
while time.time()<(start+Tadd):
x=random.uniform(0,1)
if x<0.5:
dat=time.time()
print dat
else:
pass
The output is something was this.
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
1482896418.95
So my question is:
Is it viable or "realistic" for me to code up this way? Or am I better off reading a text file line by line. eg read the 1st line process, read the 2nd line process, .... My intention is actually to read sensor data for robot localisation. But, which is the best simulation. I was thinking that perhaps I can use an event to produce data from my mouse. Can someone provide insight and suggestions on how I can go about this? Or am I better off just diving straight into the practical setting from a simulated setting and buy an ultrasound sensor.
Or if I am on the right track, and this is a good enough simulation. How do I make my time intervals ,in this case, less sensitive so that each "time"(dat) is distinct from the other.
You simply produce a random number between and add it to the current time. This is assuming you don't need time in the past only.
Edit: Now the code will generate timestamps in increasing order, separated by an average of one second.