Quantcast
Channel: Most efficient way to order a list by a preset random - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Answer by FlorianH for Most efficient way to order a list by a preset random

$
0
0

The most efficient way probably is to create a completely random array order and cache that for every user.

Except for the MySQL sollution postet above, you may use php in a very similar style: You can use the session id as a start for the random number generator and than shuffle the array using that "random" number. By doing that, every user recieves a differently sorted list, whenever he requests your site (at least as long as the session does not expire).

<?php  $array = array("Cat", "Dog", "Mouse");  session_start();  $session_id_int = (int)session_id();  srand($session_id_int);  echo '<pre>BEFORE:'.PHP_EOL;  print_r($array);  shuffle($array);  echo 'AFTER:'.PHP_EOL;  print_r($array);

Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>