core: added random & random-between to char, random to string

This commit is contained in:
hellerve 2017-12-28 18:10:38 +01:00
parent b561713add
commit 6897606f39
3 changed files with 10 additions and 1 deletions

View File

@ -5,6 +5,12 @@
(register from-int (Fn [Int] Char))
(register copy (Fn [&Char] Char))
(defn random []
(from-int (Int.random) 255))
(defn random-between [a b]
(from-int (Int.random-between (to-int a) (to-int b)) 255))
(defn meaning [char-ref]
(cond
(= @char-ref \0) 0

View File

@ -75,6 +75,9 @@
(defn empty? [s]
(Int.= (count s) 0))
(defn random-sized [n]
(from-chars (Array.repeat n Char.random)))
)
(defmodule StringCopy

View File

@ -437,7 +437,7 @@ double Double_random() {
double Double_random_MINUS_between(double lower, double upper) {
float diff = upper - lower;
float r = ((float)(rand() % INT_MAX)) / ((float)INT_MAX);
double r = ((double)(rand() % INT_MAX)) / ((double)INT_MAX);
return lower + diff * r;
}