#9 Polishing shuffle
This commit is contained in:
		
							parent
							
								
									33c9a877d2
								
							
						
					
					
						commit
						fd92ba9d8f
					
				
					 1 changed files with 13 additions and 3 deletions
				
			
		|  | @ -1,12 +1,23 @@ | |||
| module Shuffle ( | ||||
|     shuffle | ||||
| module Shuffle | ||||
| ( shuffle | ||||
| ) where | ||||
| 
 | ||||
| import Data.List | ||||
| import System.Random | ||||
| 
 | ||||
| ---------------------------------------------------------------------- | ||||
| -- Shuffle a list so that the elements of the list are randomly     -- | ||||
| -- perumated.                                                       -- | ||||
| ---------------------------------------------------------------------- | ||||
| 
 | ||||
| ----------------------------- Constants ------------------------------ | ||||
| 
 | ||||
| -- The seed used to generate random numbers. | ||||
| seed :: Int | ||||
| seed = 20 | ||||
| 
 | ||||
| ---------------------------------------------------------------------- | ||||
| 
 | ||||
| -- Shuffle a list of values. | ||||
| shuffle :: [a] -> [a] | ||||
| shuffle l = map (l !!) $ generateIndices $ length l | ||||
|  | @ -19,6 +30,5 @@ generateIndices size = take size uniqueList | |||
|           uniqueList = nub randomList | ||||
| 
 | ||||
| -- Generate a random generator | ||||
| -- TODO Écht random maken? | ||||
| randomGen :: StdGen | ||||
| randomGen = mkStdGen seed | ||||
|  |  | |||
		Reference in a new issue