This commit is contained in:
Ingy döt Net 2013-06-05 21:47:54 +00:00
parent 1f1ad49427
commit 6f050a029e
2496 changed files with 37609 additions and 3031 deletions

View file

@ -0,0 +1,15 @@
#include <iostream>
#include <random>
#include <vector>
int main( ) {
std::vector<int> numbers { 11 , 88 , -5 , 13 , 4 , 121 , 77 , 2 } ;
std::random_device seed ;
// generator
std::mt19937 engine( seed( ) ) ;
// number distribution
std::uniform_int_distribution<int> choose( 0 , numbers.size( ) - 1 ) ;
std::cout << "random element picked : " << numbers[ choose( engine ) ]
<< " !\n" ;
return 0 ;
}

View file

@ -1,7 +1,6 @@
import std.stdio, std.random;
void main() {
auto items = ["foo", "bar", "baz"];
auto r = items[uniform(0, $)];
writeln(r);
const items = ["foo", "bar", "baz"];
items[uniform(0, $)].writeln;
}

View file

@ -0,0 +1,8 @@
% Implemented by Arjun Sunel
-module(pick_random).
-export([main/0]).
main() ->
List =[1,2,3,4,5],
index = random:uniform(length(List)),
lists:nth(index,List).

View file

@ -1,3 +1 @@
(1..6).roll; # return 1 random value in the range 1 through 6
(1..6).roll(3); # return a list of 3 random values in the range 1 through 6
(1..6).roll(*); # return a lazy infinite list of random values in the range 1 through 6
say (1, 2, 3).pick;

View file

@ -1,5 +1,3 @@
# define the deck
constant deck = 2..9, <J Q K A> X~ <♠ ♣ ♥ ♦>;
deck.pick; # Pick a card
deck.pick(5); # Draw 5
deck.pick(*); # Get a shuffled deck
(1..6).roll; # return 1 random value in the range 1 through 6
(1..6).roll(3); # return a list of 3 random values in the range 1 through 6
(1..6).roll(*); # return a lazy infinite list of random values in the range 1 through 6

View file

@ -1 +1,5 @@
@array[@array * rand]
# define the deck
constant deck = 2..9, <J Q K A> X~ <♠ ♣ ♥ ♦>;
deck.pick; # Pick a card
deck.pick(5); # Draw 5
deck.pick(*); # Get a shuffled deck

View file

@ -1 +1 @@
say Bool.pick; # returns either True or False
@array[@array * rand]

View file

@ -0,0 +1 @@
say Bool.pick; # returns either True or False

View file

@ -0,0 +1,3 @@
#lang racket
(define (pick-item l)
(list-ref l (random (length l))))