From: David N. <jud...@ad...> - 2003-09-17 20:56:38
|
I think I've come up with a good function for randomizing timed events. Can you tell I've been in a coding mood lately? It takes two arguments. The first is the same as the time_now function, '6:45 PM' for example. The second is an offset in minutes (60), seconds (:45), or minutes and seconds (2:30). The function returns true at some random time between the time specified and the offset. The offset can only be positive and if you restart between the time specified and the random offset, it won't fire. David ----- Original Message ----- From: "Bruce Winter" <br...@mi...> To: <mis...@li...> Sent: Monday, September 15, 2003 9:09 PM Subject: RE: [misterhouse-users] randomizing time for an event > > This is really a newbie question, and I would > > eventually figure out how to do it, but it would save > > me a couple of hours of fiddling if someone would just > > give me the syntax... I understand the basic idea of > > time_cron and time_random, but not enough to just > > write it down. > > > > THE GOAL: > > I want the lights to go off at $HourOff plus or minus > > a number of $RandomMinutes, says plus or minus 20 > > minutes at the most, the exact time being random > > within the range $HourOff - 20 and $HourOff +20. > > > > How do I write this command? > > We don't have a built in command for this, as I have not figured out a good > way to do this yet. The trick here is you need it to fire once and only > once, per day, so you need to pick your random number once per day. > > Something like this should work: > > my $spec; > $spec = sprintf "$Time_Now %s 0:%02d", ((rand(1) > .5) ? '+' : '-'), > rand(20) if $Reload or $New_Day; > > But I'm not sure if or how to package this up into a function. > > Bruce > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > ________________________________________________________ > To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365 > |