Commit a6089b89 authored by Mart Lubbers's avatar Mart Lubbers

Separate ggenString so that it can be modified

parent 83f28313
Pipeline #13135 passed with stage
in 36 seconds
...@@ -39,6 +39,18 @@ generic ggen a :: !GenState -> [a] ...@@ -39,6 +39,18 @@ generic ggen a :: !GenState -> [a]
genState :: GenState genState :: GenState
/**
* Generates an infinite list of random strings
*
* @param The maximum length of the strings
* @param The factor for which the probability decreases for longer strings
* @param Minimum character value
* @param Maximum character value
* @param A list of random numbers (e.g. aStream)
* @result An inifinite list of strings
*/
ggenString :: Int Real Int Int RandomStream -> [String]
derive ggen Int, Bool, Real, Char, String derive ggen Int, Bool, Real, Char, String
derive ggen UNIT, PAIR, EITHER, CONS of gcd, OBJECT of gtd, FIELD of d, RECORD of grd derive ggen UNIT, PAIR, EITHER, CONS of gcd, OBJECT of gtd, FIELD of d, RECORD of grd
derive ggen (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,) derive ggen (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)
......
...@@ -186,19 +186,22 @@ where ...@@ -186,19 +186,22 @@ where
Nothing -> f s Nothing -> f s
Just limit -> take limit $ f s Just limit -> take limit $ f s
ggen{|String|} s = ["hello world!","Gast","": rndStrings aStream] ggenString :: Int Real Int Int RandomStream -> [String]
ggenString maxlen factor minchar maxchar stream = rndStrings stream
where where
rndStrings [len:rnd] rndStrings [len:rnd]
# len = toInt ((randIntToReal len) ^ 8.0 * (fromInt StrLen - 0.5)) # len = toInt ((randIntToReal len) ^ factor * (fromInt maxlen - 0.5))
# (chars,rnd) = seqList (repeatn len genElem) rnd # (chars,rnd) = seqList (repeatn len genElem) rnd
string = {c \\ c<-chars} string = {c \\ c<-chars}
= [string:rndStrings rnd] = [string:rndStrings rnd]
where where
genElem :: RandomStream -> .(Char, RandomStream) genElem :: RandomStream -> .(Char, RandomStream)
genElem [r:rnd] = (toChar (32+((abs r) rem 94)), rnd) genElem [r:rnd] = (toChar (minchar+((abs r) rem (maxchar-minchar))), rnd)
randIntToReal :: Int -> Real randIntToReal :: Int -> Real
randIntToReal x = (toReal x + if (x >= 0) 0.0 4294967296.0) / 4294967295.0 randIntToReal x = (toReal x + if (x >= 0) 0.0 4294967296.0) / 4294967295.0
ggen{|String|} s = ["hello world!","Gast","":ggenString StrLen 4.0 32 126 aStream]
derive ggen (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,) derive ggen (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)
derive ggen [], [!], [ !], [!!] derive ggen [], [!], [ !], [!!]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment