1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
############################################################################
#
# File: shuffile.icn
#
# Subject: Program to shuffle lines in a file
#
# Author: Ralph E. Griswold
#
# Date: May 12, 1996
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# This program writes a version of the input file with the lines
# shuffled. For example, the result of shuffling
#
# On the Future!-how it tells
# Of the rapture that impells
# To the swinging and the ringing
# Of the bells, bells, bells-
# Of the bells, bells, bells, bells,
# Bells, bells, bells-
# To the rhyming and the chiming of the bells!
#
# is
#
# To the rhyming and the chiming of the bells!
# To the swinging and the ringing
# Bells, bells, bells-
# Of the bells, bells, bells-
# On the Future!-how it tells
# Of the bells, bells, bells, bells,
# Of the rapture that impells
#
# The following options are supported:
#
# -s i Set random seed to i; default 0
# -r Set random seed using randomize(); overrides -s
#
# Limitation:
#
# This program stores the input file in memory and shuffles pointers to
# the lines; there must be enough memory available to store the entire
# file.
#
############################################################################
#
# Links: options, random
#
############################################################################
link options
link random
procedure main(args)
local opts, L
opts := options(args, "rs+")
&random := \opts["s"]
if \opts["r"] then randomize()
L := []
every put(L, !&input)
every write(!shuffle(L))
end
|