mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 13:37:57 +03:00
core: added random & random-between to char, random to string
This commit is contained in:
parent
b561713add
commit
6897606f39
@ -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
|
||||
|
@ -75,6 +75,9 @@
|
||||
|
||||
(defn empty? [s]
|
||||
(Int.= (count s) 0))
|
||||
|
||||
(defn random-sized [n]
|
||||
(from-chars (Array.repeat n Char.random)))
|
||||
)
|
||||
|
||||
(defmodule StringCopy
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user