Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,2 +1,4 @@
---
category:
- Randomness
note: Basic language learning

View file

@ -0,0 +1,23 @@
# pick a random element from an array of strings #
OP PICKRANDOM = ( []STRING list )STRING:
BEGIN
INT number of elements = ( UPB list - LWB list ) + 1;
INT random element =
ENTIER ( next random * ( number of elements ) );
list[ LWB list + random element ]
END; # PICKRANDOM #
# can define additional operators for other types of array #
main: (
[]STRING days = ( "Sunday", "Monday", "Tuesday", "Wednesday"
, "Thursday", "Friday", "Saturday"
);
print( ( PICKRANDOM days, newline ) )
)

View file

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
class RandomElementPicker {
static void Main() {
var list = new List<int>(new[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
var rng = new Random();
var randomElement = list[rng.Next(list.Count)];
Console.WriteLine("I picked element {0}", randomElement);
}
}

View file

@ -0,0 +1,11 @@
defmodule Random do
def init() do
:random.seed(:erlang.now())
end
def pick_element(list) do
Enum.at(list, :random.uniform(Enum.count(list)) - 1)
end
end
Random.init()
IO.puts Random.pick_element(1..20)

View file

@ -4,5 +4,5 @@
main() ->
List =[1,2,3,4,5],
index = random:uniform(length(List)),
lists:nth(index,List).
Index = random:uniform(length(List)),
lists:nth(Index,List).

View file

@ -0,0 +1,2 @@
lst = [1, 3, 5, 8, 10]
> randomPick(lst)

View file

@ -0,0 +1,3 @@
import Test.QuickCheck (generate, elements)
x <- (generate . elements) [1, 2, 3]

View file

@ -0,0 +1,4 @@
random_element(l):= part(l, 1+random(length(l)));
/* (%i1) random_element(['a, 'b, 'c]);
(%o1) c
*/

View file

@ -0,0 +1,2 @@
?- random_member(M, [a, b, c, d, e, f, g, h, i, j]).
M = i.

View file

@ -0,0 +1,3 @@
val a = (1 to 10).toList
println(scala.util.Random.shuffle(a).head)