Reference - Data handling - random


App: manual - Page: miscellaneous/handling


App: regression/framework - Page: options/random_above_the_rows_gives_each_row_once
PHP
HTML
options/random_above_the_rows_gives_each_row_once.pad
Result
{data 'xs'}[1,2,3,4,5]{/data}{data 'ks'}{"a":1,"b":2,"c":3}{/data}{xs random=8, sort}{$xs}{/xs} {ks random=5, sort}{$ks}{/ks} {xs random=7, duplicates, sort}x{/xs}


App: regression/framework - Page: options/random_gives_back_as_many_as_asked_for
PHP
HTML
options/random_gives_back_as_many_as_asked_for.pad
Result
{data 'n'}
[1,2,3]
{/data}
{n random=2}
x
{/n}


App: regression/framework - Page: options/random_takes_a_count_that_is_no_number_as_one
PHP
HTML
options/random_takes_a_count_that_is_no_number_as_one.pad
Result
{data 'n'}
[1,2,3]
{/data}
{n random='-1'}
x
{/n}|{n random='2.5'}
x
{/n}|{n random='abc'}
x
{/n}|{n random=0}
x
{/n}|{n random}
x
{/n}


App: regression/framework - Page: options/rows_keyed_by_number_keep_their_keys_under_every_handler
PHP
options/rows_keyed_by_number_keep_their_keys_under_every_handler.php
HTML
options/rows_keyed_by_number_keep_their_keys_under_every_handler.pad
Result
<?php

// A set keyed by id - the keys are part of the rows, {&key} names them - and a list, which
// stays a list: numbered from 0 again after the handler.

$ks = [ 10 => [ 'n' => 3 ], 20 => [ 'n' => 1 ], 30 => [ 'n' => 2 ] ];
$xs = [ 'a', 'b', 'c' ];

?>
first:[{ks first=2}{&key},{/ks}] last:[{ks last=2}{&key},{/ks}] reverse:[{ks reverse}{&key},{/ks}] sort:[{ks sort='n'}{&key},{/ks}] splice:[{ks splice='1|1'}{&key},{/ks}] trim:[{ks trim}{&key},{/ks}] left:[{ks trim, left}{&key},{/ks}] random:[{ks random=3, orderly}{&key},{/ks}] list:[{xs reverse}{&key}{$xs},{/xs}][{xs last=2}{&key}{$xs},{/xs}][{xs splice='0|1'}{&key}{$xs},{/xs}]


App: regression/framework - Page: sequence/a_random_count_of_0_draws_nothing
PHP
HTML
sequence/a_random_count_of_0_draws_nothing.pad
Result
{sequence '1..5', randomize=0}[{$sequence}]@else@none{/sequence}|{data 'd'}[1,2,3,4]{/data}{d random=0}[{$d}]@else@none{/d}