WeixiangYan/CodeTransOcean huggingface dataset:
Task: Walk a directory_Recursively






PHP: function findFiles($dir = '.', $pattern = '/./'){
  $prefix = $dir . '/';
  $dir = dir($dir);
  while (false !== ($file = $dir->read())){
    if ($file === '.' || $file === '..') continue;
    $file = $prefix . $file;
    if (is_dir($file)) findFiles($file, $pattern);
    if (preg_match($pattern, $file)){
      echo $file . "\n";
    }
  }
}
findFiles('./foo', '/\.bar$/');






Ada: with Ada.Directories;  use Ada.Directories;
with Ada.Text_IO;

procedure Test_Directory_Walk is
   procedure Walk (Name : String; Pattern : String) is
      procedure Print (Item : Directory_Entry_Type) is
      begin
         Ada.Text_IO.Put_Line (Full_Name (Item));
      end Print;
      procedure Walk (Item : Directory_Entry_Type) is
      begin
         if Simple_Name (Item) /= "." and then Simple_Name (Item) /= ".." then
            Walk (Full_Name (Item), Pattern);
         end if;
      exception
         when Name_Error => null;
      end Walk;
   begin
      Search (Name, Pattern, (others => True), Print'Access);
      Search (Name, "", (Directory => True, others => False), Walk'Access);
   end Walk;
begin
   Walk (".", "*.adb");
end Test_Directory_Walk;
Task: Keyboard input_Keypress check



C#: string chr = string.Empty;
if(Console.KeyAvailable)
  chr = Console.ReadKey().Key.ToString();









Ada: Ch : Character;
Available : Boolean;

Ada.Text_IO.Get_Immediate (Ch, Available);
Task: Keyboard input_Keypress check

C: #include <stdio.h>
#include <termios.h>  
#include <unistd.h>   
#include <fcntl.h>

void set_mode(int want_key)
{
	static struct termios old, new;
	if (!want_key) {
		tcsetattr(STDIN_FILENO, TCSANOW, &old);
		return;
	}

	tcgetattr(STDIN_FILENO, &old);
	new = old;
	new.c_lflag &= ~(ICANON | ECHO);
	tcsetattr(STDIN_FILENO, TCSANOW, &new);
}

int get_key()
{
	int c = 0;
	struct timeval tv;
	fd_set fs;
	tv.tv_usec = tv.tv_sec = 0;

	FD_ZERO(&fs);
	FD_SET(STDIN_FILENO, &fs);
	select(STDIN_FILENO + 1, &fs, 0, 0, &tv);

	if (FD_ISSET(STDIN_FILENO, &fs)) {
		c = getchar();
		set_mode(0);
	}
	return c;
}

int main()
{
	int c;
	while(1) {
		set_mode(1);
                
                fflush(stdout);
		while (!(c = get_key())) usleep(10000);
		printf("key %d\n", c);
	}
}











Ada: Ch : Character;
Available : Boolean;

Ada.Text_IO.Get_Immediate (Ch, Available);
Task: Keyboard input_Keypress check




Go: package main

import (
    "log"
    "time"

    gc "code.google.com/p/goncurses"
)

func main() {
    s, err := gc.Init()
    if err != nil {
        log.Fatal("init:", err)
    }
    defer gc.End()
    gc.Cursor(0)
    s.Move(20, 0)
    s.Print("Key check in ")
    for i := 3; i >= 1; i-- {
        s.MovePrint(20, 13, i)
        s.Refresh()
        time.Sleep(500 * time.Millisecond)
    }








Ada: Ch : Character;
Available : Boolean;

Ada.Text_IO.Get_Immediate (Ch, Available);
Task: Keyboard input_Keypress check





Java: import java.awt.event.*;
import javax.swing.*;

public class Test extends JFrame {

    Test() {
        addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                int keyCode = e.getKeyCode();
                System.out.println(keyCode);
            }
        });
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            Test f = new Test();
            f.setFocusable(true);
            f.setVisible(true);
        });
    }
}







Ada: Ch : Character;
Available : Boolean;

Ada.Text_IO.Get_Immediate (Ch, Available);
Task: Keyboard input_Keypress check







Python: 

from __future__ import absolute_import, division, unicode_literals, print_function

import tty, termios
import sys
if sys.version_info.major < 3:
    import thread as _thread
else:
    import _thread
import time


try:
    from msvcrt import getch  
except ImportError:
    def getch():   
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

def keypress():
    global char
    char = getch()

def main():
    global char
    char = None
    _thread.start_new_thread(keypress, ())

    while True:
        if char is not None:
            try:
                print("Key pressed is " + char.decode('utf-8'))
            except UnicodeDecodeError:
                print("character can not be decoded, sorry!")
                char = None
            _thread.start_new_thread(keypress, ())
            if char == 'q' or char == '\x1b':  
                exit()
            char = None
        print("Program is running")
        time.sleep(1)

if __name__ == "__main__":
    main()





Ada: Ch : Character;
Available : Boolean;

Ada.Text_IO.Get_Immediate (Ch, Available);
Task: Keyboard input_Keypress check

C: #include <stdio.h>
#include <termios.h>  
#include <unistd.h>   
#include <fcntl.h>

void set_mode(int want_key)
{
	static struct termios old, new;
	if (!want_key) {
		tcsetattr(STDIN_FILENO, TCSANOW, &old);
		return;
	}

	tcgetattr(STDIN_FILENO, &old);
	new = old;
	new.c_lflag &= ~(ICANON | ECHO);
	tcsetattr(STDIN_FILENO, TCSANOW, &new);
}

int get_key()
{
	int c = 0;
	struct timeval tv;
	fd_set fs;
	tv.tv_usec = tv.tv_sec = 0;

	FD_ZERO(&fs);
	FD_SET(STDIN_FILENO, &fs);
	select(STDIN_FILENO + 1, &fs, 0, 0, &tv);

	if (FD_ISSET(STDIN_FILENO, &fs)) {
		c = getchar();
		set_mode(0);
	}
	return c;
}

int main()
{
	int c;
	while(1) {
		set_mode(1);
                
                fflush(stdout);
		while (!(c = get_key())) usleep(10000);
		printf("key %d\n", c);
	}
}
Task: Keyboard input_Keypress check



C#: string chr = string.Empty;
if(Console.KeyAvailable)
  chr = Console.ReadKey().Key.ToString();
Task: Keyboard input_Keypress check





Java: import java.awt.event.*;
import javax.swing.*;

public class Test extends JFrame {

    Test() {
        addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                int keyCode = e.getKeyCode();
                System.out.println(keyCode);
            }
        });
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            Test f = new Test();
            f.setFocusable(true);
            f.setVisible(true);
        });
    }
}
Task: Keyboard input_Keypress check







Python: 

from __future__ import absolute_import, division, unicode_literals, print_function

import tty, termios
import sys
if sys.version_info.major < 3:
    import thread as _thread
else:
    import _thread
import time


try:
    from msvcrt import getch  
except ImportError:
    def getch():   
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

def keypress():
    global char
    char = getch()

def main():
    global char
    char = None
    _thread.start_new_thread(keypress, ())

    while True:
        if char is not None:
            try:
                print("Key pressed is " + char.decode('utf-8'))
            except UnicodeDecodeError:
                print("character can not be decoded, sorry!")
                char = None
            _thread.start_new_thread(keypress, ())
            if char == 'q' or char == '\x1b':  
                exit()
            char = None
        print("Program is running")
        time.sleep(1)

if __name__ == "__main__":
    main()
Task: Keyboard input_Keypress check




Go: package main

import (
    "log"
    "time"

    gc "code.google.com/p/goncurses"
)

func main() {
    s, err := gc.Init()
    if err != nil {
        log.Fatal("init:", err)
    }
    defer gc.End()
    gc.Cursor(0)
    s.Move(20, 0)
    s.Print("Key check in ")
    for i := 3; i >= 1; i-- {
        s.MovePrint(20, 13, i)
        s.Refresh()
        time.Sleep(500 * time.Millisecond)
    }
Task: Deal cards for FreeCell

C: #include <stdio.h>
#include <stdlib.h>
#include <locale.h>

wchar_t s_suits[] = L"♣♦♥♠", s_nums[] = L"A23456789TJQK";

#define RMAX32 ((1U << 31) - 1)
static int seed = 1;
int  rnd(void) { return (seed = (seed * 214013 + 2531011) & RMAX32) >> 16; }
void srnd(int x) { seed = x; }

void show(const int *c)
{
	int i;
	for (i = 0; i < 52; c++) {
		printf("  \033[%dm%lc\033[m%lc", 32 - (1 + *c) % 4 / 2,
			s_suits[*c % 4], s_nums[*c / 4]);
		if (!(++i % 8) || i == 52) putchar('\n');
	}
}

void deal(int s, int *t)
{
	int i, j;
	srnd(s);

	for (i = 0; i < 52; i++) t[i] = 51 - i;
	for (i = 0; i < 51; i++) {
		j = 51 - rnd() % (52 - i);
		s = t[i], t[i] = t[j], t[j] = s;
	}
}

int main(int c, char **v)
{
	int s, card[52];
	if (c < 2 || (s = atoi(v[1])) <= 0) s = 11982;

	setlocale(LC_ALL, "");

	deal(s, card);
	printf("Hand %d\n", s);
	show(card);

	return 0;
}











Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure FreeCell is
   type State is mod 2**31;
   type Deck is array (0..51) of String(1..2);

   package Random is
      procedure Init(Seed: State);
      function Rand return State;
   end Random;
   package body Random is
      S : State := State'First;
      procedure Init(Seed: State) is begin S := Seed; end Init;
      function Rand return State is begin
         S := S * 214013 + 2531011;  return S / 2**16;
      end Rand;
   end Random;

   procedure Deal (num : State) is
      thedeck : Deck;  pick : State;
      Chars : constant String := "A23456789TJQKCDHS";
   begin
      for i in thedeck'Range loop
         thedeck(i):= Chars(i/4+1) & Chars(i mod 4 + 14);
      end loop;
      Random.Init(num);
      for i in 0..51 loop
         pick := Random.Rand mod State(52-i);
         Put(thedeck(Natural(pick))&' ');
         if (i+1) mod 8 = 0 then New_Line; end if;
         thedeck(Natural(pick)) := thedeck(51-i);
      end loop; New_Line;
   end Deal;

begin
   Deal(1);
   New_Line;
   Deal(617);
end FreeCell;
Task: Deal cards for FreeCell


C++: #include <windows.h>
#include <iostream>


using namespace std;


class fc_dealer
{
public:
    void deal( int game )
    {
	_gn = game;
	fillDeck();
	shuffle();
	display();
    }

private:
    void fillDeck()
    {
	int p = 0;
	for( int c = 0; c < 13; c++ )
	    for( int s = 0; s < 4; s++ )
		_cards[p++] = c | s << 4;
    }

    void shuffle()
    {
	srand( _gn );
	int cc = 52, nc, lc;
	while( cc )
	{
	    nc = rand() % cc;
	    lc = _cards[--cc];
	    _cards[cc] = _cards[nc];
	    _cards[nc] = lc;
	}
    }

    void display()
    {
	char* suit = "CDHS";
	char* symb = "A23456789TJQK";
	int z = 0;
	cout << "GAME #" << _gn << endl << "=======================" << endl;
	for( int c = 51; c >= 0; c-- )
	{
	    cout << symb[_cards[c] & 15] << suit[_cards[c] >> 4] << " ";
	    if( ++z >= 8 )
	    {
		cout << endl;
		z = 0;
	    }
	}
    }

    int _cards[52], _gn;
};

int main( int argc, char* argv[] )
{
    fc_dealer dealer;
    int gn;
    while( true )
    {
	cout << endl << "Game number please ( 0 to QUIT ): "; cin >> gn;
	if( !gn ) break;

	system( "cls" );
	dealer.deal( gn );
	cout << endl << endl;
    }
    return 0;
}











Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure FreeCell is
   type State is mod 2**31;
   type Deck is array (0..51) of String(1..2);

   package Random is
      procedure Init(Seed: State);
      function Rand return State;
   end Random;
   package body Random is
      S : State := State'First;
      procedure Init(Seed: State) is begin S := Seed; end Init;
      function Rand return State is begin
         S := S * 214013 + 2531011;  return S / 2**16;
      end Rand;
   end Random;

   procedure Deal (num : State) is
      thedeck : Deck;  pick : State;
      Chars : constant String := "A23456789TJQKCDHS";
   begin
      for i in thedeck'Range loop
         thedeck(i):= Chars(i/4+1) & Chars(i mod 4 + 14);
      end loop;
      Random.Init(num);
      for i in 0..51 loop
         pick := Random.Rand mod State(52-i);
         Put(thedeck(Natural(pick))&' ');
         if (i+1) mod 8 = 0 then New_Line; end if;
         thedeck(Natural(pick)) := thedeck(51-i);
      end loop; New_Line;
   end Deal;

begin
   Deal(1);
   New_Line;
   Deal(617);
end FreeCell;
Task: Deal cards for FreeCell




Go: package main

import (
    "fmt"
    "math"
    "math/rand"
    "os"
    "strconv"
    "time"
)

const sSuits = "CDHS"
const sNums = "A23456789TJQK"
const rMax32 = math.MaxInt32

var seed = 1

func rnd() int {
    seed = (seed*214013 + 2531011) & rMax32
    return seed >> 16
}

func deal(s int) []int {
    seed = s
    t := make([]int, 52)
    for i := 0; i < 52; i++ {
        t[i] = 51 - i
    }
    for i := 0; i < 51; i++ {
        j := 51 - rnd()%(52-i)
        t[i], t[j] = t[j], t[i]
    }
    return t
}

func show(cs []int) {
    for i, c := range cs {
        fmt.Printf(" %c%c", sNums[c/4], sSuits[c%4])
        if (i+1)%8 == 0 || i+1 == len(cs) {
            fmt.Println()
        }
    }
}

func main() {
    var game int
    switch len(os.Args) {
    case 1:
        rand.Seed(time.Now().UnixNano())
        game = 1 + rand.Intn(32000)
    case 2:
        var err error
        game, err = strconv.Atoi(os.Args[1])
        if err == nil && game >= 1 && game <= 32000 {
            break
        }
        fallthrough
    default:
        fmt.Println("usage: deal [game]")
        fmt.Println("       where game is a number in the range 1 to 32000")
        return
    }
    fmt.Printf("\nGame #%d\n", game)
    show(deal(game))
}








Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure FreeCell is
   type State is mod 2**31;
   type Deck is array (0..51) of String(1..2);

   package Random is
      procedure Init(Seed: State);
      function Rand return State;
   end Random;
   package body Random is
      S : State := State'First;
      procedure Init(Seed: State) is begin S := Seed; end Init;
      function Rand return State is begin
         S := S * 214013 + 2531011;  return S / 2**16;
      end Rand;
   end Random;

   procedure Deal (num : State) is
      thedeck : Deck;  pick : State;
      Chars : constant String := "A23456789TJQKCDHS";
   begin
      for i in thedeck'Range loop
         thedeck(i):= Chars(i/4+1) & Chars(i mod 4 + 14);
      end loop;
      Random.Init(num);
      for i in 0..51 loop
         pick := Random.Rand mod State(52-i);
         Put(thedeck(Natural(pick))&' ');
         if (i+1) mod 8 = 0 then New_Line; end if;
         thedeck(Natural(pick)) := thedeck(51-i);
      end loop; New_Line;
   end Deal;

begin
   Deal(1);
   New_Line;
   Deal(617);
end FreeCell;
Task: Deal cards for FreeCell





Java: import java.util.Arrays;

public class Shuffler {
	
	private int seed;
	
	private String[] deck = {
			"AC", "AD", "AH", "AS",
			"2C", "2D", "2H", "2S",
			"3C", "3D", "3H", "3S",
			"4C", "4D", "4H", "4S",
			"5C", "5D", "5H", "5S",
			"6C", "6D", "6H", "6S",
			"7C", "7D", "7H", "7S",
			"8C", "8D", "8H", "8S",
			"9C", "9D", "9H", "9S",
			"TC", "TD", "TH", "TS",
			"JC", "JD", "JH", "JS",
			"QC", "QD", "QH", "QS",
			"KC", "KD", "KH", "KS",
	};
	
	private int random() {
		seed = (214013 * seed + 2531011) & Integer.MAX_VALUE;
		return seed >> 16;
	}
	
	
	private String[] getShuffledDeck() {
		String[] deck = Arrays.copyOf(this.deck, this.deck.length);
		for(int i = deck.length - 1; i > 0; i--) {
			int r = random() % (i + 1);
			String card = deck[r];
			deck[r] = deck[i];
			deck[i] = card;
		}
		return deck;
	}
	
	
	public void dealGame(int seed) {
		this.seed = seed;
		String[] shuffledDeck = getShuffledDeck();
		for(int count = 1, i = shuffledDeck.length - 1; i >= 0; count++, i--) {
			System.out.print(shuffledDeck[i]);
			if(count % 8 == 0) {
				System.out.println();
			} else {
				System.out.print(" ");
			}
		}
		System.out.println();
	}
	
	public static void main(String[] args) {
		Shuffler s = new Shuffler();
		s.dealGame(1);
		System.out.println();
		s.dealGame(617);
	}
	
}







Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure FreeCell is
   type State is mod 2**31;
   type Deck is array (0..51) of String(1..2);

   package Random is
      procedure Init(Seed: State);
      function Rand return State;
   end Random;
   package body Random is
      S : State := State'First;
      procedure Init(Seed: State) is begin S := Seed; end Init;
      function Rand return State is begin
         S := S * 214013 + 2531011;  return S / 2**16;
      end Rand;
   end Random;

   procedure Deal (num : State) is
      thedeck : Deck;  pick : State;
      Chars : constant String := "A23456789TJQKCDHS";
   begin
      for i in thedeck'Range loop
         thedeck(i):= Chars(i/4+1) & Chars(i mod 4 + 14);
      end loop;
      Random.Init(num);
      for i in 0..51 loop
         pick := Random.Rand mod State(52-i);
         Put(thedeck(Natural(pick))&' ');
         if (i+1) mod 8 = 0 then New_Line; end if;
         thedeck(Natural(pick)) := thedeck(51-i);
      end loop; New_Line;
   end Deal;

begin
   Deal(1);
   New_Line;
   Deal(617);
end FreeCell;
Task: Deal cards for FreeCell







Python: def randomGenerator(seed=1):
    max_int32 = (1 << 31) - 1
    seed = seed & max_int32

    while True:
        seed = (seed * 214013 + 2531011) & max_int32
        yield seed >> 16

def deal(seed):
    nc = 52
    cards = list(range(nc - 1, -1, -1))
    rnd = randomGenerator(seed)
    for i, r in zip(range(nc), rnd):
        j = (nc - 1) - r % (nc - i)
        cards[i], cards[j] = cards[j], cards[i]
    return cards

def show(cards):
    l = ["A23456789TJQK"[int(c/4)] + "CDHS"[c%4] for c in cards]
    for i in range(0, len(cards), 8):
        print(" ".join(l[i : i+8]))

if __name__ == '__main__':
    from sys import argv
    seed = int(argv[1]) if len(argv) == 2 else 11982
    print("Hand {}".format(seed))
    deck = deal(seed)
    show(deck)





Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure FreeCell is
   type State is mod 2**31;
   type Deck is array (0..51) of String(1..2);

   package Random is
      procedure Init(Seed: State);
      function Rand return State;
   end Random;
   package body Random is
      S : State := State'First;
      procedure Init(Seed: State) is begin S := Seed; end Init;
      function Rand return State is begin
         S := S * 214013 + 2531011;  return S / 2**16;
      end Rand;
   end Random;

   procedure Deal (num : State) is
      thedeck : Deck;  pick : State;
      Chars : constant String := "A23456789TJQKCDHS";
   begin
      for i in thedeck'Range loop
         thedeck(i):= Chars(i/4+1) & Chars(i mod 4 + 14);
      end loop;
      Random.Init(num);
      for i in 0..51 loop
         pick := Random.Rand mod State(52-i);
         Put(thedeck(Natural(pick))&' ');
         if (i+1) mod 8 = 0 then New_Line; end if;
         thedeck(Natural(pick)) := thedeck(51-i);
      end loop; New_Line;
   end Deal;

begin
   Deal(1);
   New_Line;
   Deal(617);
end FreeCell;
Task: Deal cards for FreeCell

C: #include <stdio.h>
#include <stdlib.h>
#include <locale.h>

wchar_t s_suits[] = L"♣♦♥♠", s_nums[] = L"A23456789TJQK";

#define RMAX32 ((1U << 31) - 1)
static int seed = 1;
int  rnd(void) { return (seed = (seed * 214013 + 2531011) & RMAX32) >> 16; }
void srnd(int x) { seed = x; }

void show(const int *c)
{
	int i;
	for (i = 0; i < 52; c++) {
		printf("  \033[%dm%lc\033[m%lc", 32 - (1 + *c) % 4 / 2,
			s_suits[*c % 4], s_nums[*c / 4]);
		if (!(++i % 8) || i == 52) putchar('\n');
	}
}

void deal(int s, int *t)
{
	int i, j;
	srnd(s);

	for (i = 0; i < 52; i++) t[i] = 51 - i;
	for (i = 0; i < 51; i++) {
		j = 51 - rnd() % (52 - i);
		s = t[i], t[i] = t[j], t[j] = s;
	}
}

int main(int c, char **v)
{
	int s, card[52];
	if (c < 2 || (s = atoi(v[1])) <= 0) s = 11982;

	setlocale(LC_ALL, "");

	deal(s, card);
	printf("Hand %d\n", s);
	show(card);

	return 0;
}
Task: Deal cards for FreeCell


C++: #include <windows.h>
#include <iostream>


using namespace std;


class fc_dealer
{
public:
    void deal( int game )
    {
	_gn = game;
	fillDeck();
	shuffle();
	display();
    }

private:
    void fillDeck()
    {
	int p = 0;
	for( int c = 0; c < 13; c++ )
	    for( int s = 0; s < 4; s++ )
		_cards[p++] = c | s << 4;
    }

    void shuffle()
    {
	srand( _gn );
	int cc = 52, nc, lc;
	while( cc )
	{
	    nc = rand() % cc;
	    lc = _cards[--cc];
	    _cards[cc] = _cards[nc];
	    _cards[nc] = lc;
	}
    }

    void display()
    {
	char* suit = "CDHS";
	char* symb = "A23456789TJQK";
	int z = 0;
	cout << "GAME #" << _gn << endl << "=======================" << endl;
	for( int c = 51; c >= 0; c-- )
	{
	    cout << symb[_cards[c] & 15] << suit[_cards[c] >> 4] << " ";
	    if( ++z >= 8 )
	    {
		cout << endl;
		z = 0;
	    }
	}
    }

    int _cards[52], _gn;
};

int main( int argc, char* argv[] )
{
    fc_dealer dealer;
    int gn;
    while( true )
    {
	cout << endl << "Game number please ( 0 to QUIT ): "; cin >> gn;
	if( !gn ) break;

	system( "cls" );
	dealer.deal( gn );
	cout << endl << endl;
    }
    return 0;
}
Task: Deal cards for FreeCell





Java: import java.util.Arrays;

public class Shuffler {
	
	private int seed;
	
	private String[] deck = {
			"AC", "AD", "AH", "AS",
			"2C", "2D", "2H", "2S",
			"3C", "3D", "3H", "3S",
			"4C", "4D", "4H", "4S",
			"5C", "5D", "5H", "5S",
			"6C", "6D", "6H", "6S",
			"7C", "7D", "7H", "7S",
			"8C", "8D", "8H", "8S",
			"9C", "9D", "9H", "9S",
			"TC", "TD", "TH", "TS",
			"JC", "JD", "JH", "JS",
			"QC", "QD", "QH", "QS",
			"KC", "KD", "KH", "KS",
	};
	
	private int random() {
		seed = (214013 * seed + 2531011) & Integer.MAX_VALUE;
		return seed >> 16;
	}
	
	
	private String[] getShuffledDeck() {
		String[] deck = Arrays.copyOf(this.deck, this.deck.length);
		for(int i = deck.length - 1; i > 0; i--) {
			int r = random() % (i + 1);
			String card = deck[r];
			deck[r] = deck[i];
			deck[i] = card;
		}
		return deck;
	}
	
	
	public void dealGame(int seed) {
		this.seed = seed;
		String[] shuffledDeck = getShuffledDeck();
		for(int count = 1, i = shuffledDeck.length - 1; i >= 0; count++, i--) {
			System.out.print(shuffledDeck[i]);
			if(count % 8 == 0) {
				System.out.println();
			} else {
				System.out.print(" ");
			}
		}
		System.out.println();
	}
	
	public static void main(String[] args) {
		Shuffler s = new Shuffler();
		s.dealGame(1);
		System.out.println();
		s.dealGame(617);
	}
	
}
Task: Deal cards for FreeCell







Python: def randomGenerator(seed=1):
    max_int32 = (1 << 31) - 1
    seed = seed & max_int32

    while True:
        seed = (seed * 214013 + 2531011) & max_int32
        yield seed >> 16

def deal(seed):
    nc = 52
    cards = list(range(nc - 1, -1, -1))
    rnd = randomGenerator(seed)
    for i, r in zip(range(nc), rnd):
        j = (nc - 1) - r % (nc - i)
        cards[i], cards[j] = cards[j], cards[i]
    return cards

def show(cards):
    l = ["A23456789TJQK"[int(c/4)] + "CDHS"[c%4] for c in cards]
    for i in range(0, len(cards), 8):
        print(" ".join(l[i : i+8]))

if __name__ == '__main__':
    from sys import argv
    seed = int(argv[1]) if len(argv) == 2 else 11982
    print("Hand {}".format(seed))
    deck = deal(seed)
    show(deck)