# how to create random numbers at fixed rate in real time

``````deltime=readline(prompt="Please enter deliery date and time\t")       # for input of date and time
#> Please enter deliery date and time
T=as.POSIXlt.character(deltime)                                          # to pass the time in formate R accepts
#> Error in as.POSIXlt.character(deltime): character string is not in a standard unambiguous format
orders=200
if(Sys.time() < T){
repeat{
f = function(){
a= rpois(orders, lambda = 10)
return( a=as.integer(a))

}

print(a)}
if(Sys.time()+60*30==T){
break}

}else if(Sys.time()+60*30>T){
print("Enter Valid Time")
}
#> [1] "Enter Valid Time"
``````

Created on 2019-10-06 by the reprex package (v0.3.0)

Hello,

Thanks for creating a reprex, but could you please provide some more background information on what it is you're trying to do and what is causing the issue?

Kind regards,
PJ

actually i want to generate numbers continuously in 30 mins if i set 1 number in 1 min so it should generate 1 number after 1 min till 30 mins there should be 30 numbers randomly generated please guide.

Hi,

I hope I got your request correctly. This is my implementation:

``````nPerMin = 1
durationMin = 30

i = 0
while(i < nPerMin * durationMin){
print(runif(1, 0, 1))
i = i + 1
Sys.sleep(60 / nPerMin)
}

``````

The key is the `Sys.sleep` function which will pause the code for any number of seconds given. I created the code in such a way you can set a variable that specifies how many numbers you like per minute and for how many minutes you like it to go on. Note that this will work only accurately if you use integers.

Hope this helps,
PJ

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.