1

function

2

3

do

4

=

check_whether_sorted

5

6

// If the array is sorted, we're done.

7

if

==

True

8

return

9

end if

10

11

// If array is not sorted, randomize it and try again!

12

=

randomize_array

13

14

while

==

False

15

16

end function

17

18

19

function

20

21

=

length

22

23

for

=

1

to

=

24

25

// Get a random array position after "i"

26

=

random_integer

27

28

//Swap the values at the two positions

29

swap

30

31

end for

32

33

return

34

35

end function

36

37

38

function

39

40

=

length

41

42

for

=

1

to

=

43

44

// If any two consecutive values are out of order

45

// then the array is not sorted.

46

if

>

+

1

47

return False

48

end if

49

50

end for

51

52

// If nothing was out of order, the array is sorted.

53

return True

54

55

end function

56