On Drupal 10 public frontend (and reported in previous Drupal 8 and 9 versions), it seems sometimes any caching (whether core, Views cache, or any server-side) can affect the randomized sorting and display of the contents. Sometimes, we need to randomize the display of contents for a requirement, example displaying Advertisements randomly on every page refresh or any required random settings.

Possible solutions

  • Disable all performance cache, especially Javascript or any other custom caching (for testing and troubleshooting purposes only, this is however is not acceptable as core cache is essentially important for production)
  • Disable Views cache for the display – found under Views > Display > Advanced > Caching, set to None; the default in Views is tag-based
  • Time-based caching for Views cache – same as above only this time implement a time-based setting if this is applicable and preferred instead
  • Use/Install module Views Random Seed – https://www.drupal.org/project/views_random_seed, for this to work:
    • turn off Views caching for the page or block display
    • remove any core Random sorting criteria, instead choose Random Seed sorting from the criteria options and let the module perform its settings

References and related issues

Some useful information from Drupal community forum that might be related and helpful:

  • https://www.drupal.org/forum/support/post-installation/2015-11-19/views-random-not-working-resolved
  • https://www.drupal.org/project/drupal/issues/2930156

Sample Setup using Views Random Seed

For a requirement that needs to randomly display ads banners, the following settings seemed to work:

  • Reuse seed from another view display: None
  • User seed type: Use a different seed per user
  • Anonymous sessions: Yes (check). Start sessions for anonymous users, which impacts performance.
    If left unchecked, the seed will be the same for all anonymous users
  • Reset seed: Custom, set to 1 second (any page refresh within the 1 second time threshold will ensure the random display changes)

Drupal views, random display sorting criteria does not work, Views Random Seed alternative solution