thx, take a random seed form the session and shuffle data is a good
idea

looks like slow because of amount od data, but I can save the random
numbers for each row in the database and make 2 selects, one > then
random(seed) and join it with the other, <= random(seed)

On 22. Sep., 14:31 h., Tim Chase <[email protected]>
wrote:
> > I need ordering units in random order, but keep the order for browsing
> > per pages and also keep the order for changeable filtering options,
> > like startswith and contains. What are the best solutions? There is
> > huge amount of units and I read the order by RANDOM() or especialy
> > MySQL RAND() is very slow. Have you any experience/solutions?
>
> My first thought would be to bring back the results in a
> predictable order that can't be changed.  That will ensure that
> they don't change over time.  You can then use the "random"
> module's seed/shuffle calls to shuffle the given instance.  You
> merely have to set the seed in your session information:
>
>    import random
>    ...
>    data = list(MyObject.objects.filter(...).order('predictable'))
>    seed = request.GET.get('seed', random.randint(0, 10000))
>    r = random.Random()
>    r.seed(seed)
>    r.shuffle(data)
>    do_stuff(data, seed) # pass the seed to the template
>      # paginator so it can be passed in on the next page
>
> This works because if you take data in a known-order sequence,
> set the random-generator's seed, and then shuffle the data based
> on that sed, you should get the same pseudo-random order each
> time you use the same seed.  So the trick is to choose a random
> seed once per "browsing".
>
> -tim
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to