Perhaps line 51 should be:
sec := time.Duration(rand.ExpFloat64() * float64(t.period))
to get

tick. (0s)
tick. (5.872982ms)
tick. (5.37282ms)
tick. (12.310533ms)
...
instead of
tick. (0s)
tick. (0s)
tick. (10ms)
tick. (30ms)
tick. (0s)
tick. (0s)


Den onsdag 26 september 2018 kl. 17:33:29 UTC+2 skrev Sebastien Binet:
>
>
>
> On Wed, Sep 26, 2018 at 2:29 PM David Wahlstedt <david.wah...@gmail.com 
> <javascript:>> wrote:
>
>> Thanks--nice!
>> Will this be less reliable than the built-in Ticker (that uses 
>> runtimeTimer), besides the intentional randomness?
>>
>
> modulo the possible bug(s) I may have unintentionally introduced, I think 
> it should be as reliable.
> (perhaps a bit less efficient than runtimeTimer, I haven't had the 
> intellectual curiosity to look at what runtimeTimer does.)
>
> -s
>  
>
>>
>> /David
>>
>> Den tisdag 25 september 2018 kl. 18:43:33 UTC+2 skrev Sebastien Binet:
>>>
>>>
>>>
>>> On Tue, Sep 25, 2018 at 11:34 AM David Wahlstedt <david.wah...@gmail.com> 
>>> wrote:
>>>
>>>> Hi,
>>>> What would be a nice way to implement a ticker that generates events 
>>>> according to a Poisson process?
>>>> The built-in Ticker in ticker.go uses a runtimeTimer that has a field 
>>>> called period.
>>>> I would like to implement a "random ticker" such that each tick 
>>>> interval is random, using ExpFloat64() * d, with average duration d, 
>>>> instead of a fixed interval.
>>>> I could have a go routine that sleeps a random amount of time in a 
>>>> loop, but it would be nice to use something similar to the ticker.
>>>>
>>>
>>> just for fun:  https://play.golang.org/p/kt0qVQ41E1C
>>> (yes, it uses a goroutine that sleeps a random amount of time in a loop.)
>>>
>>> -s
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to