Congratulations on your progress, :) Welcome to monads
First thing you have to keep in mind is to restrict the time spent in imperative world. So take out as much stuff as you can from the do ..., and refactor them into smaller non-IO code.
import System.Environment (getArgs)
Another advice is to avoid magic numbers in your code. If there are any, they should be declared in a highly visible area along with their purpose rather than buried deep in the code.
minLen = 10000
main = do
args <- getArgs
writeFile (getFileName args) =<< rndStr (getFileSize args)
where getFileSize  = minLen
getFileSize (x:xs) = read x :: Int
getFileName [x] = x ++ "-output.txt"
getFileName (x:y:) = y
As you can see, the reason you can't use rndStr directly is that rndStr uses IO. So it cannot be directly used as a function. You can think of it this way. rndStr returns some thing that is wrapped in a box. You need special constructs to unbox it, and the special construct is either <- . You might also notice that main has the same kind of signature.
That isn't a really good analogy, and I am not the best teacher :). So if you really want to understand what happens, it might be better to read any simple monad tutorial.
rndStr :: Int -> IO String
rndStr n = sequence . replicate n . randomRIO $ (' ', '~')
Try this approach if it makes better sense to you. When you start ghci, use this flag
On the prompt after loading your program, try to execute writeFile which was not accepting
(rndStr number) earlier, but this time, instead of that expression, replace it by ?check
> writeFile (getFileName ["5"] ) ?check
You will get back some thing like
Unbound implicit parameter (?check::String)
arising from a use of implicit parameter `?check'
In the second argument of `writeFile', namely `?check'
In the expression: writeFile (getFileName ["5"]) ?check
In an equation for `it': it = writeFile (getFileName ["5"]) ?check
Ignore every thing except the second line, the Unknown implict .. tells you that ghc expected any exprssion in place of ?check would be a string.
Now try finding the type of our expression
> :t rndStr 5
rndStr 5 :: IO String
As you can see,
rndStr number has a different type
IO String than the expected
String. This is the reason you cant use
rndStr number there, and why we have to do all that above.
Note that my statement
writeFile (getFileName args) =<< rndStr (getFileSize args) is really same as
str <- rndStr (getFileSize args)
writeFile (getFileName args) str
Try to work out how it is so.