Re: [Mojolicious] Re: Randomness in a template
You're welcome :) On Thursday, August 21, 2014 2:32:25 PM UTC+2, Stefan Adams wrote: > > > On Thu, Aug 21, 2014 at 7:11 AM, Jan Henning Thorsen < > jan.henn...@thorsen.pm> wrote: > >> sub startup { >> my $app = shift; >> # this code is run in parent process >> >> # this next_tick() code is run once in each forked child >> Mojo::IOLoop->next_tick(sub { srand }); >> > > Thanks, Jan! This exactly solved it for me! > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at http://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
Re: [Mojolicious] Re: Randomness in a template
On Thu, Aug 21, 2014 at 7:11 AM, Jan Henning Thorsen wrote: > sub startup { > my $app = shift; > # this code is run in parent process > > # this next_tick() code is run once in each forked child > Mojo::IOLoop->next_tick(sub { srand }); > Thanks, Jan! This exactly solved it for me! -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at http://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
[Mojolicious] Re: Randomness in a template
Stefan: It's probably because the random seed has been initialized in the parent process. See http://perldoc.perl.org/5.10.1/functions/srand.html for more details. You could try to call srand in each chile process: sub startup { my $app = shift; # this code is run in parent process # this next_tick() code is run once in each forked child Mojo::IOLoop->next_tick(sub { srand }); } On Thursday, August 21, 2014 8:00:05 AM UTC+2, Stefan Adams wrote: > > I have a template: > > % use List::Util 'shuffle'; > % my @roster = shuffle @$roster; > > And when using hypnotoad I don't get a new randomized roster list on every > page refresh. It seems that I have about 4 possible randomized lists that > my browser may display, presumale because I have 4 hypnotoad processes > running and handling requests. > > I assume this is expected. What can I do to get the behavior that I'm > looking for which is a randomized list on every page refresh? > > Naturally, with morbo, it's a new randomized list on every page refresh. > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at http://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.