Data update

This commit is contained in:
Ingy döt Net 2025-08-11 18:05:26 -07:00
parent 4d5544505c
commit 4924dd0264
3073 changed files with 55820 additions and 4408 deletions

View file

@ -0,0 +1,9 @@
# PRN in range(0,n)
create or replace function prn(n) as trunc(random() * n)::BIGINT;
create or replace function list_random(lst) as
lst[ 1 + prn(length(lst)) ] ;
## Example:
select histogram( r )
from (select list_random( [1,2,3] ) as r from range(0,1000) _(n));

View file

@ -0,0 +1,4 @@
local ordinals = {"first", "second", "third", "fourth", "fifth", "sixth"}
for _ = 1, 6 do
print(ordinals[math.random(1, #ordinals)])
end

View file

@ -0,0 +1,6 @@
; for Chicken Scheme
(import (chicken random))
(define (pick_random x)
(list-ref x (pseudo-random-integer (length x)))
)

View file

@ -0,0 +1,79 @@
# seed rng
set seed [expr { srand([clock clicks]) }]
# return a list of random selections of items from a list
proc random_items { item_list {n 1} {dups no} } {
# use item_list in place as items
upvar 1 $item_list items
set result {}
set max [llength $items]
if { $n > $max} {set n $max}
set count 0
while { $count < $n } {
# random integer index 0..len-1
set idx [expr { int(rand() * $max)} ]
# pick item
set item [lindex $items $idx]
# check for dups
if {$dups eq no} {
set srch [lsearch $result $item]
if {$srch > -1} { continue }
}
lappend result $item
incr count
}
return $result
}
# randomize a list in place
proc randomize {item_list} {
upvar 1 $item_list items
set len [llength $items]
set items [random_items items $len]
}
# return a new shuffled list
proc shuffle {items} {
set len [llength $items]
return [random_items items $len]
}
# test cases
set animals {
dog cat bird ant fish
horse pig cow snake mouse
whale worm bug spider deer
bee bear human gecko octopus
}
# 1 item default
set guess [random_items animals]
puts stdout "guess: $guess \n"
# in place shuffle
randomize animals
# list of 4 random items, no dups
set A [random_items animals 4]
set B [random_items animals 5]
set C [random_items animals 6]
set dashline [string repeat "-" 30]
foreach a {$A $B $C} {
puts stdout $dashline
puts stdout "${a}"
}
puts stdout $dashline