1 | :- multifile generate/2. | |
2 | :- multifile shrink/3. | |
3 | ||
4 | :- use_module(library(random),[random/3]). | |
5 | ||
6 | % Options: | |
7 | % size:Length, alph only a-z | |
8 | ||
9 | generate(atom(Options),Value) :- | |
10 | % given or random size | |
11 | (member(size:Size,Options) | |
12 | -> Size >= 0 | |
13 | ; random(1,20,Size)) , | |
14 | % only alphabetic with no capital letters, else random chars with special signs | |
15 | (member(alph,Options) | |
16 | -> generate(list(between(97,122),[size:Size]),Codes) | |
17 | ; generate(list(between(33,127),[size:Size]),Codes)) , | |
18 | atom_codes(Value,Codes). | |
19 | ||
20 | shrink(atom(_),Value,Shrunken) :- | |
21 | atom_codes(Value,CodeList) , | |
22 | shrink(list,CodeList,ShrunkenList) , | |
23 | ShrunkenList \= [] , | |
24 | atom_codes(Shrunken,ShrunkenList). |