How would I go about making this run from 250 - 350 second loops?
Asked
Active
Viewed 82 times
1 Answers
4
Try using the random() package. Read the docs.
Modifying the original function:
import random
random.seed()
def run_periodically(start, end, interval, func):
event_time = start
while event_time < end:
s.enterabs(event_time, 0, func, ())
event_time += interval + random.random(-60, 60)
s.run()
Once upon a time when I was definitely not writing a script to make (fake) money on a web-based game, I used a mixture of cron, Selenium, and python's random() with a gaussian distribution to log myself on and take care of things. Good times.

Dan Anderson
- 480
- 2
- 12
-
First of all, lol brilliant! Secondly I havnt started using the start and end times in the run periodically code, when setting a start time, how do you format the time? One other question, the for loop there `while event_time < end:` what if you wanted to schedule the start time as 22:30 in the evening and the end time as 21:30 the following day? Would that render said loop broken? Kind regards AEA – AEA Jun 04 '13 at 03:16
-
The scheduler class is maybe a little more complicated than you need to deal with right now (it's not that bad, just particular). Try using time.sleep() instead to familiarize yourself with timekeeping in code. – Dan Anderson Jun 04 '13 at 03:20
-
Should i have asked said question in a new thread? I'm not entirely sure of the rules. – AEA Jun 04 '13 at 03:32
-
Hi whilst trying to run the code in the way you supplied It didnt work,: 'module' object is not callable. I then supposed that `+ random` should actually by `+random.seed` to which i got the error .seed can take 2 arguments, and apparently I have provided 3. :s – AEA Jun 04 '13 at 03:51
-
Hey dan appreciate the advice, but I learn much better by manipulating code, from examples.I do read up on functions all the time, but sometimes its hard to know where to start. – AEA Jun 05 '13 at 00:43
-
I ran the code import random random.seed() `import datetime from sched import scheduler from time import time, sleep ######Code to loop the script and set up scheduling time s = scheduler(time, sleep) def run_periodically(start, end, interval, func): event_time = start while event_time < end: s.enterabs(event_time, 0, func, ()) event_time += interval + random.random(-5, 45) s.run()` I get the call back, `random() takes no arguments (2 given)` – AEA Jun 05 '13 at 01:16
-
For anyone who accidentally stumbles across this thread the answer to my woes was the following: http://stackoverflow.com/questions/16930228/use-of-the-random-function-to-randomise-scheduled-tasks – AEA Jun 05 '13 at 02:35