You are here

views_random_seed.module in Views random seed 8

Same filename and directory in other branches
  1. 6 views_random_seed.module
  2. 7 views_random_seed.module

Adds a random order handler with seed. If a constant integer argument N is specified, it is used as the seed value, which produces a repeatable sequence of column values. This makes it possible to have paging and not having items show up twice.

See http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#funct...

For postgresql we need to use another technique as an integer is not supported in the random() function. We use 'select setseed(integer)' which random() will use afterwards.

See http://www.postgresql.org/docs/current/interactive/functions-math.html

File

views_random_seed.module
View source
<?php

/**
 * @file
 * Adds a random order handler with seed. If a constant integer argument N is
 * specified, it is used as the seed value, which produces a repeatable sequence
 * of column values. This makes it possible to have paging and not having items
 * show up twice.
 *
 * See http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_rand
 *
 * For postgresql we need to use another technique as an integer is not
 * supported in the random() function. We use 'select setseed(integer)' which
 * random() will use afterwards.
 *
 * See http://www.postgresql.org/docs/current/interactive/functions-math.html
 */

/**
 * Implements hook_views_data()
 */
function views_random_seed_views_data() {
  $data['views']['random_seed'] = [
    'title' => t('Random seed'),
    'help' => t('Randomize the display order with a seed which makes paging possible.') . '<br />If you want to cache this view, use time-based caching.',
    'sort' => [
      'id' => 'views_random_seed_random',
    ],
  ];
  return $data;
}

Functions