Commit 0ab4a7cc authored by Steffen Michels's avatar Steffen Michels

Merge branch '14-ggen-string-only-generates-string-up-to-80-chars' into 'master'

Resolve "ggen{|String|} only generates string up to 80 chars."

Closes #14

See merge request !23
parents cb445335 1bcb57fb
Pipeline #13969 passed with stage
in 41 seconds
......@@ -44,6 +44,18 @@ generic ggen a :: !GenState -> [a]
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 UNIT, PAIR, EITHER, CONS of gcd, OBJECT of gtd, FIELD of d, RECORD of grd
derive ggen (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)
......@@ -52,4 +64,4 @@ derive ggen {}, {!}
maxint :: Int
minint :: Int
StrLen :== 80
StrLen :== 16384
......@@ -194,16 +194,22 @@ where
Nothing -> f s
Just limit -> take limit $ f s
ggen{|String|} s = ["hello world!","Gast": rndStrings 0 aStream]
ggenString :: Int Real Int Int RandomStream -> [String]
ggenString maxlen factor minchar maxchar stream = rndStrings stream
where
rndStrings 0 rnd = ["": rndStrings 1 rnd]
rndStrings len [r,s:rnd]
# (chars,rnd) = seqList (repeatn ((abs r) rem len) genElem) rnd
rndStrings [len:rnd]
# len = toInt ((randIntToReal len) ^ factor * (fromInt maxlen - 0.5))
# (chars,rnd) = seqList (repeatn len genElem) rnd
string = {c \\ c<-chars}
= [string:rndStrings ((len rem StrLen)+1) rnd]
= [string:rndStrings rnd]
where
genElem :: RandomStream -> .(Char, RandomStream)
genElem [r:rnd] = (toChar (32+((abs r) rem 94)), rnd)
genElem [r:rnd] = (toChar (minchar+((abs r) rem (maxchar+1-minchar))), rnd)
randIntToReal :: Int -> Real
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 [], [!], [ !], [!!]
......
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