Haskell is purely functional. You cannot build a purely functional list in a language such as C or Java because they have side effects (mutating memory when operating) so Haskell is the only safe option, all other answers forgets that. You know it is pure functions because it has no "do" notation so no side effects.
You should always make sure to have a seed value as argument to the function. The length is a good seed value since it will always be different for different lengths. Random numbers are created by scrambling the seed. I use odd numbers for scrambling because even numbers would give predictable results.
Note how recursion makes it easy to reason about runtime performance! Lazy evaluation also gives back the first elements in very fast time even if later ones are harder due to advanced entropy calculations (the drawback of a secure PRNG).
randomList = getLine >>= return . randomList' . read >>= print
where
randomList' 1 = [5]
randomList' length = reverse $
case length `mod` 2 of
0 -> [foldr (+) 1 (randomList' (length - 1))]
1 -> [length * length * 4711 `mod` 101]
2 -> [4] -- Always include all cases just in case
++ randomList' (length - 1)
Examples:
*Main> randomList
2
[5,6]
*Main> randomList
5
[92,6,5,80,9]
*Main> randomList
25
[124837,62396,31157,15562,7731,3825,1874,893,440,193,92,6,5,80,9,54,13,88,77,81,100,33,82,45,23]
*Main> randomList
36
[37,85,47,24,16,23,45,82,33,100,81,77,88,13,54,9,80,5,6,92,193,440,893,1874,3825,7731,15562,31157,62396,124837,249697,499410,998844,1997735,3995555,7991147]
15http://xkcd.com/221/ – grc – 2013-12-28T04:13:47.630
5http://dilbert.com/dyn/str_strip/000000000/00000000/0000000/000000/00000/2000/300/2318/2318.strip.gif – MultiplyByZer0 – 2013-12-28T18:22:18.250
Code-trolling is in the process of being removed, as per the official stance. This question has many answers and votes, recieved exactly 50% "keep" votes on the poll, and is one of the first [code-trolling] posts, so I am locking it for historical significance.
– Doorknob – 2014-05-11T22:21:06.480