Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7695661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:35:39+00:00 2026-05-31T21:35:39+00:00

Only began using Haskell a couple of weeks ago – I am attempting to

  • 0

Only began using Haskell a couple of weeks ago – I am attempting to randomly shuffle a list of type Card by splitting the list into two at a random point int eh list (depending on an array of random integers produced by the randomList function) and swapping the order of these two parts a number of times, but the output is not at all random, and the parse only seems to be happening once, pretty desperate as I need it working and the deadline is tonight!

randomList :: (Random a) => (a,a) -> Int -> StdGen -> [a]
randomList bnds n = take n . randomRs bnds

randomise :: [Int] -> [Card] -> [Card]
randomise [] p = p
randomise (x : xs) p = do
                    randomise xs ((drop x p) ++ (take x p))

shuffle :: Int -> [Card] -> [Card]
shuffle r p = do
          let g = mkStdGen r
          randomise(randomList (1, (length p)-1) 500 g :: [Int]) p
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:35:41+00:00Added an answer on May 31, 2026 at 9:35 pm

    You can just make a random number of permutations on your list. You can do it like:

    import System.Random
    import Data.List
    
    shuffle xs = do
        gen <- getStdGen
        let (permNum,newGen) = randomR (0,fac (length xs) -1) gen
        return $ permutation permNum xs
    

    permutation makes n permutations on the (assumed sorted) list xs. When randomizing, xs need not be sorted however.

    fac is just an implementation of the factorial function.

    shuffle makes a random number and applies that many permutations to xs.

    It’s a bit different from what you are trying to do, but it works wonders. I assumed you didn’t need to explicitly use your proposed method. You will have to implement permutation and fac yourself though.

    For help on permutation, you could look here. It’s a description to solve a Project Euler Problem, but you could use the same procedure to make n permutations.

    EDIT: I don’t know if anyone cares anymore, but I found another way to do it WAY easier:

    import System.Random
    
    randPerm :: StdGen -> [a] -> [a]
    randPerm _ []   = []
    randPerm gen xs = let (n,newGen) = randomR (0,length xs -1) gen
                          front = xs !! n
                      in  front : randPerm newGen (take n xs ++ drop (n+1) xs)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I only began learning about web development 3 weeks ago and have grasped html,
I'm working on constructing a table using only divs. I began creating the table
I've only recently began using the debugger extensively, so I'm not sure if this
A few months ago in a C# application I began using a ListBox as
Select only showing first character of option text in IE 9 Using click on
I only very recently began developing professionally. I studied OOP while at University, but
Attempting to set up Samba + OpenLDAP using nss_ldap. After joining Windows7 to Samba
I began using WCF last night to setup a simple client server that will
I began using node.js+express combo very recently and I stumbled at a need to
I have some trouble with using authlogic in my rails app, so I began

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.