Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -5,26 +5,26 @@
|
|||
TestList byte 00h,05h,10h,15h,20h,25h,30h,35h
|
||||
|
||||
.code
|
||||
|
||||
|
||||
start:
|
||||
mov ax,@data
|
||||
mov ds,ax
|
||||
|
||||
mov ax,@code
|
||||
mov es,ax
|
||||
mov ax,@data
|
||||
mov ds,ax
|
||||
|
||||
call seedXorshift32 ;seeds the xorshift rng using the computer's date and time
|
||||
|
||||
call doXorshift32
|
||||
mov ax,word ptr [ds:xorshift32_state_lo] ;retrieve the rng output
|
||||
and al,00000111b ;constrain the rng to values 0-7
|
||||
|
||||
mov bx,offset TestList
|
||||
XLAT ;translate AL according to [DS:BX]
|
||||
|
||||
call PrintHex ;display AL to the terminal
|
||||
|
||||
mov ax,@code
|
||||
mov es,ax
|
||||
|
||||
mov ax,4C00h
|
||||
int 21h ;exit program and return to MS-DOS
|
||||
call seedXorshift32 ;seeds the xorshift rng using the computer's date and time
|
||||
|
||||
call doXorshift32
|
||||
mov ax,word ptr [ds:xorshift32_state_lo] ;retrieve the rng output
|
||||
and al,00000111b ;constrain the rng to values 0-7
|
||||
|
||||
mov bx,offset TestList
|
||||
XLAT ;translate AL according to [DS:BX]
|
||||
|
||||
call PrintHex ;display AL to the terminal
|
||||
|
||||
|
||||
mov ax,4C00h
|
||||
int 21h ;exit program and return to MS-DOS
|
||||
end start
|
||||
|
|
|
|||
30
Task/Pick-random-element/Ada/pick-random-element.adb
Normal file
30
Task/Pick-random-element/Ada/pick-random-element.adb
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
with Ada.Text_IO, Ada.Numerics.Float_Random;
|
||||
|
||||
procedure Pick_Random_Element is
|
||||
|
||||
package Rnd renames Ada.Numerics.Float_Random;
|
||||
Gen: Rnd.Generator; -- used globally
|
||||
|
||||
type Char_Arr is array (Natural range <>) of Character;
|
||||
|
||||
function Pick_Random(A: Char_Arr) return Character is
|
||||
-- Chooses one of the characters of A (uniformly distributed)
|
||||
begin
|
||||
return A(A'First + Natural(Rnd.Random(Gen) * Float(A'Last)));
|
||||
end Pick_Random;
|
||||
|
||||
Vowels : Char_Arr := ('a', 'e', 'i', 'o', 'u');
|
||||
Consonants: Char_Arr := ('t', 'n', 's', 'h', 'r', 'd', 'l');
|
||||
Specials : Char_Arr := (',', '.', '?', '!');
|
||||
|
||||
begin
|
||||
Rnd.Reset(Gen);
|
||||
for J in 1 .. 3 loop
|
||||
for I in 1 .. 10 loop
|
||||
Ada.Text_IO.Put(Pick_Random(Consonants));
|
||||
Ada.Text_IO.Put(Pick_Random(Vowels));
|
||||
end loop;
|
||||
Ada.Text_IO.Put(Pick_Random(Specials) & " ");
|
||||
end loop;
|
||||
Ada.Text_IO.New_Line;
|
||||
end Pick_Random_Element;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(import std.Random)
|
||||
|
||||
(print (random:choice ["foo" "bar" "baz"]))
|
||||
|
|
@ -1,16 +1,16 @@
|
|||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
::Initializing the pseudo-array...
|
||||
::Initializing the pseudo-array...
|
||||
set "pseudo=Alpha Beta Gamma Delta Epsilon"
|
||||
set cnt=0 & for %%P in (!pseudo!) do (
|
||||
set /a cnt+=1
|
||||
set "pseudo[!cnt!]=%%P"
|
||||
set /a cnt+=1
|
||||
set "pseudo[!cnt!]=%%P"
|
||||
)
|
||||
::Do the random thing...
|
||||
::Do the random thing...
|
||||
set /a rndInt=%random% %% cnt +1
|
||||
|
||||
::Print the element corresponding to rndint...
|
||||
::Print the element corresponding to rndint...
|
||||
echo.!pseudo[%rndInt%]!
|
||||
pause
|
||||
exit /b
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ int main(){
|
|||
srand((unsigned)time(&t));
|
||||
|
||||
for(i=0;i<30;i++){
|
||||
printf("%c\n", array[rand()%10]);
|
||||
printf("%c\n", array[rand()%10]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
16
Task/Pick-random-element/COBOL/pick-random-element.cob
Normal file
16
Task/Pick-random-element/COBOL/pick-random-element.cob
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
>>SOURCE FREE
|
||||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. random-element.
|
||||
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
01 nums-area VALUE "123456789".
|
||||
03 nums PIC 9 OCCURS 9 TIMES.
|
||||
|
||||
01 random-idx PIC 9 COMP.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
COMPUTE random-idx = FUNCTION RANDOM(FUNCTION CURRENT-DATE (9:7)) * 9 + 1
|
||||
DISPLAY nums (random-idx)
|
||||
.
|
||||
END PROGRAM random-element.
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import ceylon.random {
|
||||
|
||||
DefaultRandom
|
||||
DefaultRandom
|
||||
}
|
||||
|
||||
shared void run() {
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
ar$[] = [ "spring" "summer" "autumn" "winter" ]
|
||||
print ar$[random len ar$[]]
|
||||
print ar$[random 1 len ar$[] ]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
(defun random-choice (items)
|
||||
(nth (random (length items)) items))
|
||||
|
||||
(random-choice '("a" "b" "c"))
|
||||
;; => "a"
|
||||
|
|
@ -3,6 +3,6 @@
|
|||
-export([main/0]).
|
||||
|
||||
main() ->
|
||||
List =[1,2,3,4,5],
|
||||
Index = rand:uniform(length(List)),
|
||||
lists:nth(Index,List).
|
||||
List =[1,2,3,4,5],
|
||||
Index = rand:uniform(length(List)),
|
||||
lists:nth(Index,List).
|
||||
|
|
|
|||
2
Task/Pick-random-element/Euphoria/pick-random-element.eu
Normal file
2
Task/Pick-random-element/Euphoria/pick-random-element.eu
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
constant s = {'a', 'b', 'c'}
|
||||
puts(1,s[rand($)])
|
||||
|
|
@ -3,10 +3,10 @@ use math::random;
|
|||
use datetime;
|
||||
|
||||
export fn main() void = {
|
||||
const array = ["one", "two", "three", "four", "five"];
|
||||
const seed = datetime::now();
|
||||
const seed = datetime::nsec(&seed);
|
||||
let r = math::random::init(seed: u32);
|
||||
const array = ["one", "two", "three", "four", "five"];
|
||||
const seed = datetime::now();
|
||||
const seed = datetime::nsec(&seed);
|
||||
let r = math::random::init(seed: u32);
|
||||
|
||||
fmt::printfln("{}", array[math::random::u32n(&r, len(array): u32)])!;
|
||||
fmt::printfln("{}", array[math::random::u32n(&r, len(array): u32)])!;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
local(
|
||||
my array = array('one', 'two', 3)
|
||||
my array = array('one', 'two', 3)
|
||||
)
|
||||
|
||||
#myarray -> get(integer_random(#myarray -> size, 1))
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
list = {'a','b','c'};
|
||||
list{ceil(rand(1)*length(list))}
|
||||
list{ceil(rand(1)*length(list))}
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
list = 1:1000;
|
||||
list(ceil(rand(1)*length(list)))
|
||||
list(ceil(rand(1)*length(list)))
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
(define (pick-random-element R)
|
||||
(nth (rand (length R)) R))
|
||||
(nth (rand (length R)) R))
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
1..100 | Get-Random -Count 3
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
let fruits = ["apple", "banana", "coconut", "orange", "lychee"]
|
||||
|
||||
let pickRand = arr => {
|
||||
let len = Js.Array.length(arr)
|
||||
let i = Js.Math.random_int(0, len)
|
||||
arr[i]
|
||||
}
|
||||
|
||||
Js.log(pickRand(fruits))
|
||||
63
Task/Pick-random-element/Rebol/pick-random-element.rebol
Normal file
63
Task/Pick-random-element/Rebol/pick-random-element.rebol
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
Rebol [
|
||||
title: "Rosetta code: Pick random element"
|
||||
file: %Pick_random_element.r3
|
||||
url: https://rosettacode.org/wiki/Pick_random_element
|
||||
]
|
||||
|
||||
elements: [
|
||||
"Hydrogen_H" "Helium_He" "Lithium_Li" "Beryllium_Be"
|
||||
"Boron_B" "Carbon_C" "Nitrogen_N" "Oxygen_O"
|
||||
"Fluorine_F" "Neon_Ne" "Sodium_Na" "Magnesium_Mg"
|
||||
"Aluminium_Al" "Silicon_Si" "Phosphorus_P" "Sulfur_S"
|
||||
"Chlorine_Cl" "Argon_Ar" "Potassium_K" "Calcium_Ca"
|
||||
"Scandium_Sc" "Titanium_Ti" "Vanadium_V" "Chromium_Cr"
|
||||
"Manganese_Mn" "Iron_Fe" "Cobalt_Co" "Nickel_Ni"
|
||||
"Copper_Cu" "Zinc_Zn" "Gallium_Ga" "Germanium_Ge"
|
||||
"Arsenic_As" "Selenium_Se" "Bromine_Br" "Krypton_Kr"
|
||||
"Rubidium_Rb" "Strontium_Sr" "Yttrium_Y" "Zirconium_Zr"
|
||||
"Niobium_Nb" "Molybdenum_Mo" "Technetium_Tc" "Ruthenium_Ru"
|
||||
"Rhodium_Rh" "Palladium_Pd" "Silver_Ag" "Cadmium_Cd"
|
||||
"Indium_In" "Tin_Sn" "Antimony_Sb" "Tellurium_Te"
|
||||
"Iodine_I" "Xenon_Xe" "Caesium_Cs" "Barium_Ba"
|
||||
"Lanthanum_La" "Cerium_Ce" "Praseodymium_Pr" "Neodymium_Nd"
|
||||
"Promethium_Pm" "Samarium_Sm" "Europium_Eu" "Gadolinium_Gd"
|
||||
"Terbium_Tb" "Dysprosium_Dy" "Holmium_Ho" "Erbium_Er"
|
||||
"Thulium_Tm" "Ytterbium_Yb" "Lutetium_Lu" "Hafnium_Hf"
|
||||
"Tantalum_Ta" "Tungsten_W" "Rhenium_Re" "Osmium_Os"
|
||||
"Iridium_Ir" "Platinum_Pt" "Gold_Au" "Mercury_Hg"
|
||||
"Thallium_Tl" "Lead_Pb" "Bismuth_Bi" "Polonium_Po"
|
||||
"Astatine_At" "Radon_Rn" "Francium_Fr" "Radium_Ra"
|
||||
"Actinium_Ac" "Thorium_Th" "Protactinium_Pa" "Uranium_U"
|
||||
"Neptunium_Np" "Plutonium_Pu" "Americium_Am" "Curium_Cm"
|
||||
"Berkelium_Bk" "Californium_Cf" "Einsteinium_Es" "Fermium_Fm"
|
||||
"Mendelevium_Md" "Nobelium_No" "Lawrencium_Lr" "Rutherfordium_Rf"
|
||||
"Dubnium_Db" "Seaborgium_Sg" "Bohrium_Bh" "Hassium_Hs"
|
||||
"Meitnerium_Mt" "Darmstadtium_Ds" "Roentgenium_Rg" "Copernicium_Cn"
|
||||
"Nihonium_Nh" "Flerovium_Fl" "Moscovium_Mc" "Livermorium_Lv"
|
||||
"Tennessine_Ts" "Oganesson_Og" "Ununbium_Uub" "Ununtrium_Uut"
|
||||
"Ununquadium_Uuq"
|
||||
]
|
||||
|
||||
either all [
|
||||
block? args: system/script/args
|
||||
not empty? args
|
||||
][
|
||||
label: "Specified"
|
||||
try/with [
|
||||
entry: pick elements args: to integer! first args
|
||||
][
|
||||
print ["Invalid script argument:" as-red args]
|
||||
print ["Script expects number from 1 to" length? elements]
|
||||
quit
|
||||
]
|
||||
unless entry [
|
||||
print ["Element" as-red args "hasn't been discovered yet"]
|
||||
quit
|
||||
]
|
||||
][
|
||||
label: "Random"
|
||||
entry: random/only elements
|
||||
]
|
||||
|
||||
set [name symbol] split entry #"_"
|
||||
print [label "element:" as-green name "-" as-yellow symbol]
|
||||
|
|
@ -14,22 +14,22 @@ proc random_items { item_list {n 1} {dups no} } {
|
|||
|
||||
set count 0
|
||||
|
||||
while { $count < $n } {
|
||||
while { $count < $n } {
|
||||
|
||||
# random integer index 0..len-1
|
||||
set idx [expr { int(rand() * $max)} ]
|
||||
# random integer index 0..len-1
|
||||
set idx [expr { int(rand() * $max)} ]
|
||||
|
||||
# pick item
|
||||
set item [lindex $items $idx]
|
||||
# pick item
|
||||
set item [lindex $items $idx]
|
||||
|
||||
# check for dups
|
||||
if {$dups eq no} {
|
||||
set srch [lsearch $result $item]
|
||||
if {$srch > -1} { continue }
|
||||
}
|
||||
# check for dups
|
||||
if {$dups eq no} {
|
||||
set srch [lsearch $result $item]
|
||||
if {$srch > -1} { continue }
|
||||
}
|
||||
|
||||
lappend result $item
|
||||
incr count
|
||||
lappend result $item
|
||||
incr count
|
||||
}
|
||||
return $result
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# borrowed from github.com/search?q=bashnative
|
||||
|
||||
rand() {
|
||||
printf $(( $1 * RANDOM / 32767 ))
|
||||
printf $(( $1 * RANDOM / 32767 ))
|
||||
}
|
||||
rand_element () {
|
||||
local -a th=("$@")
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@ import rand
|
|||
fn main() {
|
||||
list := ["friends", "peace", "people", "happiness", "hello", "world"]
|
||||
for index in 1..list.len + 1 {
|
||||
println(index.str() + ": " + list[rand.intn(list.len) or {}])
|
||||
println(index.str() + ": " + list[rand.intn(list.len)!])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
Function pick_random(arr)
|
||||
Set objRandom = CreateObject("System.Random")
|
||||
pick_random = arr(objRandom.Next_2(0,UBound(arr)+1))
|
||||
End Function
|
||||
|
||||
WScript.Echo pick_random(Array("a","b","c","d","e","f"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue