library(gmp) 

rand_MS <- function(n = 1, seed = 1) {
  a <- as.bigz(214013)
  c <- as.bigz(2531011)
  m <- as.bigz(2^31)
  x <- rep(as.bigz(0), n)
  x[1] <- (a * as.bigz(seed) + c)%% m
  i <- 1
  while (i < n) {
    x[i+1] <- (a * x[i] + c)%% m
    i <- i + 1
  }
  as.integer(x / 2^16)
}





dealFreeCell <- function(seedNum) {
  deck <- paste(rep(c("A",2,3,4,5,6,7,8,9,10,"J","Q","K"), each = 4), c("C","D","H","S"), sep = "")
  cards = rand_MS(52,seedNum)

  for (i in 52:1) {
    cardToPick <- (cards[53-i]%% i)+1 
    deck[c(cardToPick,i)] <- deck[c(i, cardToPick)]
  }

  deck <- rev(deck) 
  deal = matrix(c(deck,NA,NA,NA,NA),ncol = 8, byrow = TRUE)
  
  
  print(paste("Hand numer:",seedNum), quote = FALSE)
  print(deal, quote = FALSE, na.print = "")
}