-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.hs
45 lines (34 loc) · 1.24 KB
/
test.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import Data.List
import Data.Maybe
import System.Random
import Data.Char
findIndexToSplit p line = fromMaybe (-1) (findIndex p line) +1
extractWordWs line = snd (splitAt (findIndexToSplit (isSpace) line) line)
-- extractWordWs line = snd (splitAt (findIndexToSplit (=='\t') line) line)
-- extractWordWs line = snd (splitAt ((fromMaybe (-1) (findIndex (=='\t') line )) + 1) line)
extractAllWords ls = map extractWordWs ls
createRepository filename = do
contents <- readFile filename
let ls = lines contents
return (extractAllWords ls)
getRandomIndex list = randomRIO (0, (length list))
getRandomElement list = (getRandomIndex list) >>= \x -> return $ list !! x
chooseRandom list = do
index <- (getRandomIndex list)
return $ list !! index
getRandomElement2 list = do
index <- (getRandomIndex list)
list !! index
getRandomE list = do
word <- getRandomElement list
return word
printMessageAndValue title password = do
print title
print password
generatePassword size wlist = do
password <- mapM (\_ -> getRandomElement wlist) [1..size]
return password
printPassword filename passwordLength = do
ws <- createRepository filename
password <- generatePassword passwordLength ws
printMessageAndValue "generated password: " password