Debian Codegraph @

HTML/randomvar.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <HTML
3 ><HEAD
4 ><TITLE
5 >$RANDOM: generate random integer</TITLE
6 ><META
7 NAME="GENERATOR"
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
9 "><LINK
10 REL="HOME"
11 TITLE="Advanced Bash-Scripting Guide"
12 HREF="index.html"><LINK
13 REL="UP"
14 TITLE="Another Look at Variables"
15 HREF="variables2.html"><LINK
16 REL="PREVIOUS"
17 TITLE="Typing variables: declare or
18 typeset"
19 HREF="declareref.html"><LINK
20 REL="NEXT"
21 TITLE="Manipulating Variables"
22 HREF="manipulatingvars.html"><META
23 HTTP-EQUIV="Content-Style-Type"
24 CONTENT="text/css"><LINK
25 REL="stylesheet"
26 HREF="common/kde-common.css"
27 TYPE="text/css"><META
28 HTTP-EQUIV="Content-Type"
29 CONTENT="text/html; charset=iso-8859-1"><META
30 HTTP-EQUIV="Content-Language"
31 CONTENT="en"><LINK
32 REL="stylesheet"
33 HREF="common/kde-localised.css"
34 TYPE="text/css"
35 TITLE="KDE-English"><LINK
36 REL="stylesheet"
37 HREF="common/kde-default.css"
38 TYPE="text/css"
39 TITLE="KDE-Default"></HEAD
40 ><BODY
41 CLASS="SECT1"
42 BGCOLOR="#FFFFFF"
43 TEXT="#000000"
44 LINK="#AA0000"
45 VLINK="#AA0055"
46 ALINK="#AA0000"
47 STYLE="font-family: sans-serif;"
48 ><DIV
49 CLASS="NAVHEADER"
50 ><TABLE
51 SUMMARY="Header navigation table"
52 WIDTH="100%"
53 BORDER="0"
54 CELLPADDING="0"
55 CELLSPACING="0"
56 ><TR
57 ><TH
58 COLSPAN="3"
59 ALIGN="center"
60 >Advanced Bash-Scripting Guide: An in-depth exploration of the art of shell scripting</TH
61 ></TR
62 ><TR
63 ><TD
64 WIDTH="10%"
65 ALIGN="left"
66 VALIGN="bottom"
67 ><A
68 HREF="declareref.html"
69 ACCESSKEY="P"
70 >Prev</A
71 ></TD
72 ><TD
73 WIDTH="80%"
74 ALIGN="center"
75 VALIGN="bottom"
76 >Chapter 9. Another Look at Variables</TD
77 ><TD
78 WIDTH="10%"
79 ALIGN="right"
80 VALIGN="bottom"
81 ><A
82 HREF="manipulatingvars.html"
83 ACCESSKEY="N"
84 >Next</A
85 ></TD
86 ></TR
87 ></TABLE
88 ><HR
89 ALIGN="LEFT"
90 WIDTH="100%"></DIV
91 ><DIV
92 CLASS="SECT1"
93 ><H1
94 CLASS="SECT1"
95 ><A
96 NAME="RANDOMVAR"
97 ></A
98 >9.3. $RANDOM: generate random integer</H1
99 ><TABLE
100 BORDER="0"
101 WIDTH="100%"
102 CELLSPACING="0"
103 CELLPADDING="0"
104 CLASS="EPIGRAPH"
105 ><TR
106 ><TD
107 WIDTH="45%"
108 >&nbsp;</TD
109 ><TD
110 WIDTH="45%"
111 ALIGN="LEFT"
112 VALIGN="TOP"
113 ><I
114 ><P
115 ><I
116 >Anyone who attempts to generate random numbers by
117 deterministic means is, of course, living in a state of
118 sin.</I
119 ></P
120 ><P
121 ><I
122 >--John von Neumann</I
123 ></P
124 ></I
125 ></TD
126 ></TR
127 ></TABLE
128 ><P
129 ><A
130 NAME="RANDOMVAR01"
131 ></A
132 ></P
133 ><P
134 ><TT
135 CLASS="VARNAME"
136 >$RANDOM</TT
137 > is an internal Bash <A
138 HREF="functions.html#FUNCTIONREF"
139 >function</A
140 > (not a constant) that
141 returns a <I
142 CLASS="FIRSTTERM"
143 >pseudorandom</I
144 >
145
146 <A
147 NAME="AEN5817"
148 HREF="#FTN.AEN5817"
149 >[1]</A
150 >
151
152 integer in the range 0 - 32767. It should
153 <TT
154 CLASS="REPLACEABLE"
155 ><I
156 >not</I
157 ></TT
158 > be used to generate an encryption
159 key.</P
160 ><DIV
161 CLASS="EXAMPLE"
162 ><HR><A
163 NAME="EX21"
164 ></A
165 ><P
166 ><B
167 >Example 9-11. Generating random numbers</B
168 ></P
169 ><TABLE
170 BORDER="0"
171 BGCOLOR="#E0E0E0"
172 WIDTH="100%"
173 ><TR
174 ><TD
175 ><PRE
176 CLASS="PROGRAMLISTING"
177 > 1&nbsp;#!/bin/bash
178 2&nbsp;
179 3&nbsp;# $RANDOM returns a different random integer at each invocation.
180 4&nbsp;# Nominal range: 0 - 32767 (signed 16-bit integer).
181 5&nbsp;
182 6&nbsp;MAXCOUNT=10
183 7&nbsp;count=1
184 8&nbsp;
185 9&nbsp;echo
186 10&nbsp;echo "$MAXCOUNT random numbers:"
187 11&nbsp;echo "-----------------"
188 12&nbsp;while [ "$count" -le $MAXCOUNT ] # Generate 10 ($MAXCOUNT) random integers.
189 13&nbsp;do
190 14&nbsp; number=$RANDOM
191 15&nbsp; echo $number
192 16&nbsp; let "count += 1" # Increment count.
193 17&nbsp;done
194 18&nbsp;echo "-----------------"
195 19&nbsp;
196 20&nbsp;# If you need a random int within a certain range, use the 'modulo' operator.
197 21&nbsp;# This returns the remainder of a division operation.
198 22&nbsp;
199 23&nbsp;RANGE=500
200 24&nbsp;
201 25&nbsp;echo
202 26&nbsp;
203 27&nbsp;number=$RANDOM
204 28&nbsp;let "number %= $RANGE"
205 29&nbsp;# ^^
206 30&nbsp;echo "Random number less than $RANGE --- $number"
207 31&nbsp;
208 32&nbsp;echo
209 33&nbsp;
210 34&nbsp;
211 35&nbsp;
212 36&nbsp;# If you need a random integer greater than a lower bound,
213 37&nbsp;#+ then set up a test to discard all numbers below that.
214 38&nbsp;
215 39&nbsp;FLOOR=200
216 40&nbsp;
217 41&nbsp;number=0 #initialize
218 42&nbsp;while [ "$number" -le $FLOOR ]
219 43&nbsp;do
220 44&nbsp; number=$RANDOM
221 45&nbsp;done
222 46&nbsp;echo "Random number greater than $FLOOR --- $number"
223 47&nbsp;echo
224 48&nbsp;
225 49&nbsp; # Let's examine a simple alternative to the above loop, namely
226 50&nbsp; # let "number = $RANDOM + $FLOOR"
227 51&nbsp; # That would eliminate the while-loop and run faster.
228 52&nbsp; # But, there might be a problem with that. What is it?
229 53&nbsp;
230 54&nbsp;
231 55&nbsp;
232 56&nbsp;# Combine above two techniques to retrieve random number between two limits.
233 57&nbsp;number=0 #initialize
234 58&nbsp;while [ "$number" -le $FLOOR ]
235 59&nbsp;do
236 60&nbsp; number=$RANDOM
237 61&nbsp; let "number %= $RANGE" # Scales $number down within $RANGE.
238 62&nbsp;done
239 63&nbsp;echo "Random number between $FLOOR and $RANGE --- $number"
240 64&nbsp;echo
241 65&nbsp;
242 66&nbsp;
243 67&nbsp;
244 68&nbsp;# Generate binary choice, that is, "true" or "false" value.
245 69&nbsp;BINARY=2
246 70&nbsp;T=1
247 71&nbsp;number=$RANDOM
248 72&nbsp;
249 73&nbsp;let "number %= $BINARY"
250 74&nbsp;# Note that let "number &#62;&#62;= 14" gives a better random distribution
251 75&nbsp;#+ (right shifts out everything except last binary digit).
252 76&nbsp;if [ "$number" -eq $T ]
253 77&nbsp;then
254 78&nbsp; echo "TRUE"
255 79&nbsp;else
256 80&nbsp; echo "FALSE"
257 81&nbsp;fi
258 82&nbsp;
259 83&nbsp;echo
260 84&nbsp;
261 85&nbsp;
262 86&nbsp;# Generate a toss of the dice.
263 87&nbsp;SPOTS=6 # Modulo 6 gives range 0 - 5.
264 88&nbsp; # Incrementing by 1 gives desired range of 1 - 6.
265 89&nbsp; # Thanks, Paulo Marcel Coelho Aragao, for the simplification.
266 90&nbsp;die1=0
267 91&nbsp;die2=0
268 92&nbsp;# Would it be better to just set SPOTS=7 and not add 1? Why or why not?
269 93&nbsp;
270 94&nbsp;# Tosses each die separately, and so gives correct odds.
271 95&nbsp;
272 96&nbsp; let "die1 = $RANDOM % $SPOTS +1" # Roll first one.
273 97&nbsp; let "die2 = $RANDOM % $SPOTS +1" # Roll second one.
274 98&nbsp; # Which arithmetic operation, above, has greater precedence --
275 99&nbsp; #+ modulo (%) or addition (+)?
276 100&nbsp;
277 101&nbsp;
278 102&nbsp;let "throw = $die1 + $die2"
279 103&nbsp;echo "Throw of the dice = $throw"
280 104&nbsp;echo
281 105&nbsp;
282 106&nbsp;
283 107&nbsp;exit 0</PRE
284 ></TD
285 ></TR
286 ></TABLE
287 ><HR></DIV
288 ><DIV
289 CLASS="EXAMPLE"
290 ><HR><A
291 NAME="PICKCARD"
292 ></A
293 ><P
294 ><B
295 >Example 9-12. Picking a random card from a deck</B
296 ></P
297 ><TABLE
298 BORDER="0"
299 BGCOLOR="#E0E0E0"
300 WIDTH="100%"
301 ><TR
302 ><TD
303 ><PRE
304 CLASS="PROGRAMLISTING"
305 > 1&nbsp;#!/bin/bash
306 2&nbsp;# pick-card.sh
307 3&nbsp;
308 4&nbsp;# This is an example of choosing random elements of an array.
309 5&nbsp;
310 6&nbsp;
311 7&nbsp;# Pick a card, any card.
312 8&nbsp;
313 9&nbsp;Suites="Clubs
314 10&nbsp;Diamonds
315 11&nbsp;Hearts
316 12&nbsp;Spades"
317 13&nbsp;
318 14&nbsp;Denominations="2
319 15&nbsp;3
320 16&nbsp;4
321 17&nbsp;5
322 18&nbsp;6
323 19&nbsp;7
324 20&nbsp;8
325 21&nbsp;9
326 22&nbsp;10
327 23&nbsp;Jack
328 24&nbsp;Queen
329 25&nbsp;King
330 26&nbsp;Ace"
331 27&nbsp;
332 28&nbsp;# Note variables spread over multiple lines.
333 29&nbsp;
334 30&nbsp;
335 31&nbsp;suite=($Suites) # Read into array variable.
336 32&nbsp;denomination=($Denominations)
337 33&nbsp;
338 34&nbsp;num_suites=${#suite[*]} # Count how many elements.
339 35&nbsp;num_denominations=${#denomination[*]}
340 36&nbsp;
341 37&nbsp;echo -n "${denomination[$((RANDOM%num_denominations))]} of "
342 38&nbsp;echo ${suite[$((RANDOM%num_suites))]}
343 39&nbsp;
344 40&nbsp;
345 41&nbsp;# $bozo sh pick-cards.sh
346 42&nbsp;# Jack of Clubs
347 43&nbsp;
348 44&nbsp;
349 45&nbsp;# Thank you, "jipe," for pointing out this use of $RANDOM.
350 46&nbsp;exit 0</PRE
351 ></TD
352 ></TR
353 ></TABLE
354 ><HR></DIV
355 ><P
356 ><A
357 NAME="BROWNIANREF"
358 ></A
359 ></P
360 ><DIV
361 CLASS="EXAMPLE"
362 ><HR><A
363 NAME="BROWNIAN"
364 ></A
365 ><P
366 ><B
367 >Example 9-13. Brownian Motion Simulation</B
368 ></P
369 ><TABLE
370 BORDER="0"
371 BGCOLOR="#E0E0E0"
372 WIDTH="100%"
373 ><TR
374 ><TD
375 ><PRE
376 CLASS="PROGRAMLISTING"
377 > 1&nbsp;#!/bin/bash
378 2&nbsp;# brownian.sh
379 3&nbsp;# Author: Mendel Cooper
380 4&nbsp;# Reldate: 10/26/07
381 5&nbsp;# License: GPL3
382 6&nbsp;
383 7&nbsp;# ----------------------------------------------------------------
384 8&nbsp;# This script models Brownian motion:
385 9&nbsp;#+ the random wanderings of tiny particles in a fluid,
386 10&nbsp;#+ as they are buffeted by random currents and collisions.
387 11&nbsp;#+ This is colloquially known as the "Drunkard's Walk."
388 12&nbsp;
389 13&nbsp;# It can also be considered as a stripped-down simulation of a
390 14&nbsp;#+ Galton Board, a slanted board with a pattern of pegs,
391 15&nbsp;#+ down which rolls a succession of marbles, one at a time.
392 16&nbsp;#+ At the bottom is a row of slots or catch basins in which
393 17&nbsp;#+ the marbles come to rest at the end of their journey.
394 18&nbsp;# Think of it as a kind of bare-bones Pachinko game.
395 19&nbsp;# As you see by running the script,
396 20&nbsp;#+ most of the marbles cluster around the center slot.
397 21&nbsp;#+ This is consistent with the expected binomial distribution.
398 22&nbsp;# As a Galton Board simulation, the script
399 23&nbsp;#+ disregards such parameters as
400 24&nbsp;#+ board tilt-angle, rolling friction of the marbles,
401 25&nbsp;#+ angles of impact, and elasticity of the pegs.
402 26&nbsp;# To what extent does this affect the accuracy of the simulation?
403 27&nbsp;# ----------------------------------------------------------------
404 28&nbsp;
405 29&nbsp;PASSES=500 # Number of particle interactions / marbles.
406 30&nbsp;ROWS=10 # Number of "collisions" (or horiz. peg rows).
407 31&nbsp;RANGE=3 # 0 - 2 output range from $RANDOM.
408 32&nbsp;POS=0 # Left/right position.
409 33&nbsp;RANDOM=$$ # Seeds the random number generator from PID
410 34&nbsp; #+ of script.
411 35&nbsp;
412 36&nbsp;declare -a Slots # Array holding cumulative results of passes.
413 37&nbsp;NUMSLOTS=21 # Number of slots at bottom of board.
414 38&nbsp;
415 39&nbsp;
416 40&nbsp;Initialize_Slots () { # Zero out all elements of the array.
417 41&nbsp;for i in $( seq $NUMSLOTS )
418 42&nbsp;do
419 43&nbsp; Slots[$i]=0
420 44&nbsp;done
421 45&nbsp;
422 46&nbsp;echo # Blank line at beginning of run.
423 47&nbsp; }
424 48&nbsp;
425 49&nbsp;
426 50&nbsp;Show_Slots () {
427 51&nbsp;echo; echo
428 52&nbsp;echo -n " "
429 53&nbsp;for i in $( seq $NUMSLOTS ) # Pretty-print array elements.
430 54&nbsp;do
431 55&nbsp; printf "%3d" ${Slots[$i]} # Allot three spaces per result.
432 56&nbsp;done
433 57&nbsp;
434 58&nbsp;echo # Row of slots:
435 59&nbsp;echo " |__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|"
436 60&nbsp;echo " ||"
437 61&nbsp;echo # Note that if the count within any particular slot exceeds 99,
438 62&nbsp; #+ it messes up the display.
439 63&nbsp; # Running only(!) 500 passes usually avoids this.
440 64&nbsp; }
441 65&nbsp;
442 66&nbsp;
443 67&nbsp;Move () { # Move one unit right / left, or stay put.
444 68&nbsp; Move=$RANDOM # How random is $RANDOM? Well, let's see ...
445 69&nbsp; let "Move %= RANGE" # Normalize into range of 0 - 2.
446 70&nbsp; case "$Move" in
447 71&nbsp; 0 ) ;; # Do nothing, i.e., stay in place.
448 72&nbsp; 1 ) ((POS--));; # Left.
449 73&nbsp; 2 ) ((POS++));; # Right.
450 74&nbsp; * ) echo -n "Error ";; # Anomaly! (Should never occur.)
451 75&nbsp; esac
452 76&nbsp; }
453 77&nbsp;
454 78&nbsp;
455 79&nbsp;Play () { # Single pass (inner loop).
456 80&nbsp;i=0
457 81&nbsp;while [ "$i" -lt "$ROWS" ] # One event per row.
458 82&nbsp;do
459 83&nbsp; Move
460 84&nbsp; ((i++));
461 85&nbsp;done
462 86&nbsp;
463 87&nbsp;SHIFT=11 # Why 11, and not 10?
464 88&nbsp;let "POS += $SHIFT" # Shift "zero position" to center.
465 89&nbsp;(( Slots[$POS]++ )) # DEBUG: echo $POS
466 90&nbsp;
467 91&nbsp;# echo -n "$POS "
468 92&nbsp;
469 93&nbsp; }
470 94&nbsp;
471 95&nbsp;
472 96&nbsp;Run () { # Outer loop.
473 97&nbsp;p=0
474 98&nbsp;while [ "$p" -lt "$PASSES" ]
475 99&nbsp;do
476 100&nbsp; Play
477 101&nbsp; (( p++ ))
478 102&nbsp; POS=0 # Reset to zero. Why?
479 103&nbsp;done
480 104&nbsp; }
481 105&nbsp;
482 106&nbsp;
483 107&nbsp;# --------------
484 108&nbsp;# main ()
485 109&nbsp;Initialize_Slots
486 110&nbsp;Run
487 111&nbsp;Show_Slots
488 112&nbsp;# --------------
489 113&nbsp;
490 114&nbsp;exit $?
491 115&nbsp;
492 116&nbsp;# Exercises:
493 117&nbsp;# ---------
494 118&nbsp;# 1) Show the results in a vertical bar graph, or as an alternative,
495 119&nbsp;#+ a scattergram.
496 120&nbsp;# 2) Alter the script to use /dev/urandom instead of $RANDOM.
497 121&nbsp;# Will this make the results more random?
498 122&nbsp;# 3) Provide some sort of "animation" or graphic output
499 123&nbsp;# for each marble played.</PRE
500 ></TD
501 ></TR
502 ></TABLE
503 ><HR></DIV
504 ><P
505 > <SPAN
506 CLASS="emphasis"
507 ><I
508 CLASS="EMPHASIS"
509 >Jipe</I
510 ></SPAN
511 > points out a set of techniques for
512 generating random numbers within a range.
513
514 <TABLE
515 BORDER="0"
516 BGCOLOR="#E0E0E0"
517 WIDTH="100%"
518 ><TR
519 ><TD
520 ><PRE
521 CLASS="PROGRAMLISTING"
522 > 1&nbsp;# Generate random number between 6 and 30.
523 2&nbsp; rnumber=$((RANDOM%25+6))
524 3&nbsp;
525 4&nbsp;# Generate random number in the same 6 - 30 range,
526 5&nbsp;#+ but the number must be evenly divisible by 3.
527 6&nbsp; rnumber=$(((RANDOM%30/3+1)*3))
528 7&nbsp;
529 8&nbsp;# Note that this will not work all the time.
530 9&nbsp;# It fails if $RANDOM%30 returns 0.
531 10&nbsp;
532 11&nbsp;# Frank Wang suggests the following alternative:
533 12&nbsp; rnumber=$(( RANDOM%27/3*3+6 ))</PRE
534 ></TD
535 ></TR
536 ></TABLE
537 >
538 </P
539 ><P
540 > <SPAN
541 CLASS="emphasis"
542 ><I
543 CLASS="EMPHASIS"
544 >Bill Gradwohl</I
545 ></SPAN
546 > came up with an improved
547 formula that works for positive numbers.
548 <TABLE
549 BORDER="0"
550 BGCOLOR="#E0E0E0"
551 WIDTH="100%"
552 ><TR
553 ><TD
554 ><PRE
555 CLASS="PROGRAMLISTING"
556 > 1&nbsp;rnumber=$(((RANDOM%(max-min+divisibleBy))/divisibleBy*divisibleBy+min))</PRE
557 ></TD
558 ></TR
559 ></TABLE
560 >
561 </P
562 ><P
563 >Here Bill presents a versatile function that returns
564 a random number between two specified values.</P
565 ><DIV
566 CLASS="EXAMPLE"
567 ><HR><A
568 NAME="RANDOMBETWEEN"
569 ></A
570 ><P
571 ><B
572 >Example 9-14. Random between values</B
573 ></P
574 ><TABLE
575 BORDER="0"
576 BGCOLOR="#E0E0E0"
577 WIDTH="100%"
578 ><TR
579 ><TD
580 ><PRE
581 CLASS="PROGRAMLISTING"
582 > 1&nbsp;#!/bin/bash
583 2&nbsp;# random-between.sh
584 3&nbsp;# Random number between two specified values.
585 4&nbsp;# Script by Bill Gradwohl, with minor modifications by the document author.
586 5&nbsp;# Corrections in lines 187 and 189 by Anthony Le Clezio.
587 6&nbsp;# Used with permission.
588 7&nbsp;
589 8&nbsp;
590 9&nbsp;randomBetween() {
591 10&nbsp; # Generates a positive or negative random number
592 11&nbsp; #+ between $min and $max
593 12&nbsp; #+ and divisible by $divisibleBy.
594 13&nbsp; # Gives a "reasonably random" distribution of return values.
595 14&nbsp; #
596 15&nbsp; # Bill Gradwohl - Oct 1, 2003
597 16&nbsp;
598 17&nbsp; syntax() {
599 18&nbsp; # Function embedded within function.
600 19&nbsp; echo
601 20&nbsp; echo "Syntax: randomBetween [min] [max] [multiple]"
602 21&nbsp; echo
603 22&nbsp; echo -n "Expects up to 3 passed parameters, "
604 23&nbsp; echo "but all are completely optional."
605 24&nbsp; echo "min is the minimum value"
606 25&nbsp; echo "max is the maximum value"
607 26&nbsp; echo -n "multiple specifies that the answer must be "
608 27&nbsp; echo "a multiple of this value."
609 28&nbsp; echo " i.e. answer must be evenly divisible by this number."
610 29&nbsp; echo
611 30&nbsp; echo "If any value is missing, defaults area supplied as: 0 32767 1"
612 31&nbsp; echo -n "Successful completion returns 0, "
613 32&nbsp; echo "unsuccessful completion returns"
614 33&nbsp; echo "function syntax and 1."
615 34&nbsp; echo -n "The answer is returned in the global variable "
616 35&nbsp; echo "randomBetweenAnswer"
617 36&nbsp; echo -n "Negative values for any passed parameter are "
618 37&nbsp; echo "handled correctly."
619 38&nbsp; }
620 39&nbsp;
621 40&nbsp; local min=${1:-0}
622 41&nbsp; local max=${2:-32767}
623 42&nbsp; local divisibleBy=${3:-1}
624 43&nbsp; # Default values assigned, in case parameters not passed to function.
625 44&nbsp;
626 45&nbsp; local x
627 46&nbsp; local spread
628 47&nbsp;
629 48&nbsp; # Let's make sure the divisibleBy value is positive.
630 49&nbsp; [ ${divisibleBy} -lt 0 ] &#38;&#38; divisibleBy=$((0-divisibleBy))
631 50&nbsp;
632 51&nbsp; # Sanity check.
633 52&nbsp; if [ $# -gt 3 -o ${divisibleBy} -eq 0 -o ${min} -eq ${max} ]; then
634 53&nbsp; syntax
635 54&nbsp; return 1
636 55&nbsp; fi
637 56&nbsp;
638 57&nbsp; # See if the min and max are reversed.
639 58&nbsp; if [ ${min} -gt ${max} ]; then
640 59&nbsp; # Swap them.
641 60&nbsp; x=${min}
642 61&nbsp; min=${max}
643 62&nbsp; max=${x}
644 63&nbsp; fi
645 64&nbsp;
646 65&nbsp; # If min is itself not evenly divisible by $divisibleBy,
647 66&nbsp; #+ then fix the min to be within range.
648 67&nbsp; if [ $((min/divisibleBy*divisibleBy)) -ne ${min} ]; then
649 68&nbsp; if [ ${min} -lt 0 ]; then
650 69&nbsp; min=$((min/divisibleBy*divisibleBy))
651 70&nbsp; else
652 71&nbsp; min=$((((min/divisibleBy)+1)*divisibleBy))
653 72&nbsp; fi
654 73&nbsp; fi
655 74&nbsp;
656 75&nbsp; # If max is itself not evenly divisible by $divisibleBy,
657 76&nbsp; #+ then fix the max to be within range.
658 77&nbsp; if [ $((max/divisibleBy*divisibleBy)) -ne ${max} ]; then
659 78&nbsp; if [ ${max} -lt 0 ]; then
660 79&nbsp; max=$((((max/divisibleBy)-1)*divisibleBy))
661 80&nbsp; else
662 81&nbsp; max=$((max/divisibleBy*divisibleBy))
663 82&nbsp; fi
664 83&nbsp; fi
665 84&nbsp;
666 85&nbsp; # ---------------------------------------------------------------------
667 86&nbsp; # Now, to do the real work.
668 87&nbsp;
669 88&nbsp; # Note that to get a proper distribution for the end points,
670 89&nbsp; #+ the range of random values has to be allowed to go between
671 90&nbsp; #+ 0 and abs(max-min)+divisibleBy, not just abs(max-min)+1.
672 91&nbsp;
673 92&nbsp; # The slight increase will produce the proper distribution for the
674 93&nbsp; #+ end points.
675 94&nbsp;
676 95&nbsp; # Changing the formula to use abs(max-min)+1 will still produce
677 96&nbsp; #+ correct answers, but the randomness of those answers is faulty in
678 97&nbsp; #+ that the number of times the end points ($min and $max) are returned
679 98&nbsp; #+ is considerably lower than when the correct formula is used.
680 99&nbsp; # ---------------------------------------------------------------------
681 100&nbsp;
682 101&nbsp; spread=$((max-min))
683 102&nbsp; # Omair Eshkenazi points out that this test is unnecessary,
684 103&nbsp; #+ since max and min have already been switched around.
685 104&nbsp; [ ${spread} -lt 0 ] &#38;&#38; spread=$((0-spread))
686 105&nbsp; let spread+=divisibleBy
687 106&nbsp; randomBetweenAnswer=$(((RANDOM%spread)/divisibleBy*divisibleBy+min))
688 107&nbsp;
689 108&nbsp; return 0
690 109&nbsp;
691 110&nbsp; # However, Paulo Marcel Coelho Aragao points out that
692 111&nbsp; #+ when $max and $min are not divisible by $divisibleBy,
693 112&nbsp; #+ the formula fails.
694 113&nbsp; #
695 114&nbsp; # He suggests instead the following formula:
696 115&nbsp; # rnumber = $(((RANDOM%(max-min+1)+min)/divisibleBy*divisibleBy))
697 116&nbsp;
698 117&nbsp;}
699 118&nbsp;
700 119&nbsp;# Let's test the function.
701 120&nbsp;min=-14
702 121&nbsp;max=20
703 122&nbsp;divisibleBy=3
704 123&nbsp;
705 124&nbsp;
706 125&nbsp;# Generate an array of expected answers and check to make sure we get
707 126&nbsp;#+ at least one of each answer if we loop long enough.
708 127&nbsp;
709 128&nbsp;declare -a answer
710 129&nbsp;minimum=${min}
711 130&nbsp;maximum=${max}
712 131&nbsp; if [ $((minimum/divisibleBy*divisibleBy)) -ne ${minimum} ]; then
713 132&nbsp; if [ ${minimum} -lt 0 ]; then
714 133&nbsp; minimum=$((minimum/divisibleBy*divisibleBy))
715 134&nbsp; else
716 135&nbsp; minimum=$((((minimum/divisibleBy)+1)*divisibleBy))
717 136&nbsp; fi
718 137&nbsp; fi
719 138&nbsp;
720 139&nbsp;
721 140&nbsp; # If max is itself not evenly divisible by $divisibleBy,
722 141&nbsp; #+ then fix the max to be within range.
723 142&nbsp;
724 143&nbsp; if [ $((maximum/divisibleBy*divisibleBy)) -ne ${maximum} ]; then
725 144&nbsp; if [ ${maximum} -lt 0 ]; then
726 145&nbsp; maximum=$((((maximum/divisibleBy)-1)*divisibleBy))
727 146&nbsp; else
728 147&nbsp; maximum=$((maximum/divisibleBy*divisibleBy))
729 148&nbsp; fi
730 149&nbsp; fi
731 150&nbsp;
732 151&nbsp;
733 152&nbsp;# We need to generate only positive array subscripts,
734 153&nbsp;#+ so we need a displacement that that will guarantee
735 154&nbsp;#+ positive results.
736 155&nbsp;
737 156&nbsp;disp=$((0-minimum))
738 157&nbsp;for ((i=${minimum}; i&#60;=${maximum}; i+=divisibleBy)); do
739 158&nbsp; answer[i+disp]=0
740 159&nbsp;done
741 160&nbsp;
742 161&nbsp;
743 162&nbsp;# Now loop a large number of times to see what we get.
744 163&nbsp;loopIt=1000 # The script author suggests 100000,
745 164&nbsp; #+ but that takes a good long while.
746 165&nbsp;
747 166&nbsp;for ((i=0; i&#60;${loopIt}; ++i)); do
748 167&nbsp;
749 168&nbsp; # Note that we are specifying min and max in reversed order here to
750 169&nbsp; #+ make the function correct for this case.
751 170&nbsp;
752 171&nbsp; randomBetween ${max} ${min} ${divisibleBy}
753 172&nbsp;
754 173&nbsp; # Report an error if an answer is unexpected.
755 174&nbsp; [ ${randomBetweenAnswer} -lt ${min} -o ${randomBetweenAnswer} -gt ${max} ] \
756 175&nbsp; &#38;&#38; echo MIN or MAX error - ${randomBetweenAnswer}!
757 176&nbsp; [ $((randomBetweenAnswer%${divisibleBy})) -ne 0 ] \
758 177&nbsp; &#38;&#38; echo DIVISIBLE BY error - ${randomBetweenAnswer}!
759 178&nbsp;
760 179&nbsp; # Store the answer away statistically.
761 180&nbsp; answer[randomBetweenAnswer+disp]=$((answer[randomBetweenAnswer+disp]+1))
762 181&nbsp;done
763 182&nbsp;
764 183&nbsp;
765 184&nbsp;
766 185&nbsp;# Let's check the results
767 186&nbsp;
768 187&nbsp;for ((i=${minimum}; i&#60;=${maximum}; i+=divisibleBy)); do
769 188&nbsp; [ ${answer[i+disp]} -eq 0 ] \
770 189&nbsp; &#38;&#38; echo "We never got an answer of $i." \
771 190&nbsp; || echo "${i} occurred ${answer[i+disp]} times."
772 191&nbsp;done
773 192&nbsp;
774 193&nbsp;
775 194&nbsp;exit 0</PRE
776 ></TD
777 ></TR
778 ></TABLE
779 ><HR></DIV
780 ><P
781 >Just how random is <TT
782 CLASS="VARNAME"
783 >$RANDOM</TT
784 >? The best
785 way to test this is to write a script that tracks
786 the distribution of <SPAN
787 CLASS="QUOTE"
788 >"random"</SPAN
789 > numbers
790 generated by <TT
791 CLASS="VARNAME"
792 >$RANDOM</TT
793 >. Let's roll a
794 <TT
795 CLASS="VARNAME"
796 >$RANDOM</TT
797 > die a few times . . .</P
798 ><DIV
799 CLASS="EXAMPLE"
800 ><HR><A
801 NAME="RANDOMTEST"
802 ></A
803 ><P
804 ><B
805 >Example 9-15. Rolling a single die with RANDOM</B
806 ></P
807 ><TABLE
808 BORDER="0"
809 BGCOLOR="#E0E0E0"
810 WIDTH="100%"
811 ><TR
812 ><TD
813 ><PRE
814 CLASS="PROGRAMLISTING"
815 > 1&nbsp;#!/bin/bash
816 2&nbsp;# How random is RANDOM?
817 3&nbsp;
818 4&nbsp;RANDOM=$$ # Reseed the random number generator using script process ID.
819 5&nbsp;
820 6&nbsp;PIPS=6 # A die has 6 pips.
821 7&nbsp;MAXTHROWS=600 # Increase this if you have nothing better to do with your time.
822 8&nbsp;throw=0 # Number of times the dice have been cast.
823 9&nbsp;
824 10&nbsp;ones=0 # Must initialize counts to zero,
825 11&nbsp;twos=0 #+ since an uninitialized variable is null, NOT zero.
826 12&nbsp;threes=0
827 13&nbsp;fours=0
828 14&nbsp;fives=0
829 15&nbsp;sixes=0
830 16&nbsp;
831 17&nbsp;print_result ()
832 18&nbsp;{
833 19&nbsp;echo
834 20&nbsp;echo "ones = $ones"
835 21&nbsp;echo "twos = $twos"
836 22&nbsp;echo "threes = $threes"
837 23&nbsp;echo "fours = $fours"
838 24&nbsp;echo "fives = $fives"
839 25&nbsp;echo "sixes = $sixes"
840 26&nbsp;echo
841 27&nbsp;}
842 28&nbsp;
843 29&nbsp;update_count()
844 30&nbsp;{
845 31&nbsp;case "$1" in
846 32&nbsp; 0) ((ones++));; # Since a die has no "zero", this corresponds to 1.
847 33&nbsp; 1) ((twos++));; # And this to 2.
848 34&nbsp; 2) ((threes++));; # And so forth.
849 35&nbsp; 3) ((fours++));;
850 36&nbsp; 4) ((fives++));;
851 37&nbsp; 5) ((sixes++));;
852 38&nbsp;esac
853 39&nbsp;}
854 40&nbsp;
855 41&nbsp;echo
856 42&nbsp;
857 43&nbsp;
858 44&nbsp;while [ "$throw" -lt "$MAXTHROWS" ]
859 45&nbsp;do
860 46&nbsp; let "die1 = RANDOM % $PIPS"
861 47&nbsp; update_count $die1
862 48&nbsp; let "throw += 1"
863 49&nbsp;done
864 50&nbsp;
865 51&nbsp;print_result
866 52&nbsp;
867 53&nbsp;exit $?
868 54&nbsp;
869 55&nbsp;# The scores should distribute evenly, assuming RANDOM is random.
870 56&nbsp;# With $MAXTHROWS at 600, all should cluster around 100,
871 57&nbsp;#+ plus-or-minus 20 or so.
872 58&nbsp;#
873 59&nbsp;# Keep in mind that RANDOM is a ***pseudorandom*** generator,
874 60&nbsp;#+ and not a spectacularly good one at that.
875 61&nbsp;
876 62&nbsp;# Randomness is a deep and complex subject.
877 63&nbsp;# Sufficiently long "random" sequences may exhibit
878 64&nbsp;#+ chaotic and other "non-random" behavior.
879 65&nbsp;
880 66&nbsp;# Exercise (easy):
881 67&nbsp;# ---------------
882 68&nbsp;# Rewrite this script to flip a coin 1000 times.
883 69&nbsp;# Choices are "HEADS" and "TAILS."</PRE
884 ></TD
885 ></TR
886 ></TABLE
887 ><HR></DIV
888 ><P
889 >As we have seen in the last example, it is best to
890 <I
891 CLASS="FIRSTTERM"
892 >reseed</I
893 > the <TT
894 CLASS="PARAMETER"
895 ><I
896 >RANDOM</I
897 ></TT
898 >
899 generator each time it is invoked. Using the same seed
900 for <TT
901 CLASS="PARAMETER"
902 ><I
903 >RANDOM</I
904 ></TT
905 > repeats the same series
906 of numbers.
907 <A
908 NAME="AEN5857"
909 HREF="#FTN.AEN5857"
910 >[2]</A
911 >
912 (This mirrors the behavior of the
913 <TT
914 CLASS="REPLACEABLE"
915 ><I
916 >random()</I
917 ></TT
918 > function in
919 <I
920 CLASS="FIRSTTERM"
921 >C</I
922 >.)</P
923 ><DIV
924 CLASS="EXAMPLE"
925 ><HR><A
926 NAME="SEEDINGRANDOM"
927 ></A
928 ><P
929 ><B
930 >Example 9-16. Reseeding RANDOM</B
931 ></P
932 ><TABLE
933 BORDER="0"
934 BGCOLOR="#E0E0E0"
935 WIDTH="100%"
936 ><TR
937 ><TD
938 ><PRE
939 CLASS="PROGRAMLISTING"
940 > 1&nbsp;#!/bin/bash
941 2&nbsp;# seeding-random.sh: Seeding the RANDOM variable.
942 3&nbsp;# v 1.1, reldate 09 Feb 2013
943 4&nbsp;
944 5&nbsp;MAXCOUNT=25 # How many numbers to generate.
945 6&nbsp;SEED=
946 7&nbsp;
947 8&nbsp;random_numbers ()
948 9&nbsp;{
949 10&nbsp;local count=0
950 11&nbsp;local number
951 12&nbsp;
952 13&nbsp;while [ "$count" -lt "$MAXCOUNT" ]
953 14&nbsp;do
954 15&nbsp; number=$RANDOM
955 16&nbsp; echo -n "$number "
956 17&nbsp; let "count++"
957 18&nbsp;done
958 19&nbsp;}
959 20&nbsp;
960 21&nbsp;echo; echo
961 22&nbsp;
962 23&nbsp;SEED=1
963 24&nbsp;RANDOM=$SEED # Setting RANDOM seeds the random number generator.
964 25&nbsp;echo "Random seed = $SEED"
965 26&nbsp;random_numbers
966 27&nbsp;
967 28&nbsp;
968 29&nbsp;RANDOM=$SEED # Same seed for RANDOM . . .
969 30&nbsp;echo; echo "Again, with same random seed ..."
970 31&nbsp;echo "Random seed = $SEED"
971 32&nbsp;random_numbers # . . . reproduces the exact same number series.
972 33&nbsp; #
973 34&nbsp; # When is it useful to duplicate a "random" series?
974 35&nbsp;
975 36&nbsp;echo; echo
976 37&nbsp;
977 38&nbsp;SEED=2
978 39&nbsp;RANDOM=$SEED # Trying again, but with a different seed . . .
979 40&nbsp;echo "Random seed = $SEED"
980 41&nbsp;random_numbers # . . . gives a different number series.
981 42&nbsp;
982 43&nbsp;echo; echo
983 44&nbsp;
984 45&nbsp;# RANDOM=$$ seeds RANDOM from process id of script.
985 46&nbsp;# It is also possible to seed RANDOM from 'time' or 'date' commands.
986 47&nbsp;
987 48&nbsp;# Getting fancy...
988 49&nbsp;SEED=$(head -1 /dev/urandom | od -N 1 | awk '{ print $2 }'| sed s/^0*//)
989 50&nbsp;# Pseudo-random output fetched
990 51&nbsp;#+ from /dev/urandom (system pseudo-random device-file),
991 52&nbsp;#+ then converted to line of printable (octal) numbers by "od",
992 53&nbsp;#+ then "awk" retrieves just one number for SEED,
993 54&nbsp;#+ finally "sed" removes any leading zeros.
994 55&nbsp;RANDOM=$SEED
995 56&nbsp;echo "Random seed = $SEED"
996 57&nbsp;random_numbers
997 58&nbsp;
998 59&nbsp;echo; echo
999 60&nbsp;
1000 61&nbsp;exit 0</PRE
1001 ></TD
1002 ></TR
1003 ></TABLE
1004 ><HR></DIV
1005 ><P
1006 ><A
1007 NAME="URANDOMREF"
1008 ></A
1009 ></P
1010 ><DIV
1011 CLASS="NOTE"
1012 ><TABLE
1013 CLASS="NOTE"
1014 WIDTH="100%"
1015 BORDER="0"
1016 ><TR
1017 ><TD
1018 WIDTH="25"
1019 ALIGN="CENTER"
1020 VALIGN="TOP"
1021 ><IMG
1022 SRC="common/note.png"
1023 HSPACE="5"
1024 ALT="Note"></TD
1025 ><TD
1026 ALIGN="LEFT"
1027 VALIGN="TOP"
1028 ><P
1029 >The <TT
1030 CLASS="FILENAME"
1031 >/dev/urandom</TT
1032 > pseudo-device file
1033 provides a method of generating much more <SPAN
1034 CLASS="QUOTE"
1035 >"random"</SPAN
1036 >
1037 pseudorandom numbers than the <TT
1038 CLASS="VARNAME"
1039 >$RANDOM</TT
1040 >
1041 variable. <TT
1042 CLASS="USERINPUT"
1043 ><B
1044 >dd if=/dev/urandom of=targetfile
1045 bs=1 count=XX</B
1046 ></TT
1047 > creates a file of well-scattered
1048 pseudorandom numbers. However, assigning these numbers
1049 to a variable in a script requires a workaround, such
1050 as filtering through <A
1051 HREF="extmisc.html#ODREF"
1052 >od</A
1053 >
1054 (as in above example, <A
1055 HREF="textproc.html#RND"
1056 >Example 16-14</A
1057 >, and
1058 <A
1059 HREF="contributed-scripts.html#INSERTIONSORT"
1060 >Example A-36</A
1061 >), or even piping to
1062 <A
1063 HREF="filearchiv.html#MD5SUMREF"
1064 >md5sum</A
1065 > (see <A
1066 HREF="colorizing.html#HORSERACE"
1067 >Example 36-16</A
1068 >).</P
1069 ><P
1070 ><A
1071 NAME="AWKRANDOMREF"
1072 ></A
1073 ></P
1074 ><P
1075 >There are also other ways to generate pseudorandom
1076 numbers in a script. <B
1077 CLASS="COMMAND"
1078 >Awk</B
1079 > provides a
1080 convenient means of doing this.</P
1081 ><DIV
1082 CLASS="EXAMPLE"
1083 ><HR><A
1084 NAME="RANDOM2"
1085 ></A
1086 ><P
1087 ><B
1088 >Example 9-17. Pseudorandom numbers, using <A
1089 HREF="awk.html#AWKREF"
1090 >awk</A
1091 ></B
1092 ></P
1093 ><TABLE
1094 BORDER="0"
1095 BGCOLOR="#E0E0E0"
1096 WIDTH="100%"
1097 ><TR
1098 ><TD
1099 ><PRE
1100 CLASS="PROGRAMLISTING"
1101 > 1&nbsp;#!/bin/bash
1102 2&nbsp;# random2.sh: Returns a pseudorandom number in the range 0 - 1,
1103 3&nbsp;#+ to 6 decimal places. For example: 0.822725
1104 4&nbsp;# Uses the awk rand() function.
1105 5&nbsp;
1106 6&nbsp;AWKSCRIPT=' { srand(); print rand() } '
1107 7&nbsp;# Command(s)/parameters passed to awk
1108 8&nbsp;# Note that srand() reseeds awk's random number generator.
1109 9&nbsp;
1110 10&nbsp;
1111 11&nbsp;echo -n "Random number between 0 and 1 = "
1112 12&nbsp;
1113 13&nbsp;echo | awk "$AWKSCRIPT"
1114 14&nbsp;# What happens if you leave out the 'echo'?
1115 15&nbsp;
1116 16&nbsp;exit 0
1117 17&nbsp;
1118 18&nbsp;
1119 19&nbsp;# Exercises:
1120 20&nbsp;# ---------
1121 21&nbsp;
1122 22&nbsp;# 1) Using a loop construct, print out 10 different random numbers.
1123 23&nbsp;# (Hint: you must reseed the srand() function with a different seed
1124 24&nbsp;#+ in each pass through the loop. What happens if you omit this?)
1125 25&nbsp;
1126 26&nbsp;# 2) Using an integer multiplier as a scaling factor, generate random numbers
1127 27&nbsp;#+ in the range of 10 to 100.
1128 28&nbsp;
1129 29&nbsp;# 3) Same as exercise #2, above, but generate random integers this time.</PRE
1130 ></TD
1131 ></TR
1132 ></TABLE
1133 ><HR></DIV
1134 ><P
1135 >The <A
1136 HREF="timedate.html#DATEREF"
1137 >date</A
1138 > command also lends
1139 itself to <A
1140 HREF="timedate.html#DATERANDREF"
1141 >generating pseudorandom
1142 integer sequences</A
1143 >.</P
1144 ></TD
1145 ></TR
1146 ></TABLE
1147 ></DIV
1148 ></DIV
1149 ><H3
1150 CLASS="FOOTNOTES"
1151 >Notes</H3
1152 ><TABLE
1153 BORDER="0"
1154 CLASS="FOOTNOTES"
1155 WIDTH="100%"
1156 ><TR
1157 ><TD
1158 ALIGN="LEFT"
1159 VALIGN="TOP"
1160 WIDTH="5%"
1161 ><A
1162 NAME="FTN.AEN5817"
1163 HREF="randomvar.html#AEN5817"
1164 >[1]</A
1165 ></TD
1166 ><TD
1167 ALIGN="LEFT"
1168 VALIGN="TOP"
1169 WIDTH="95%"
1170 ><P
1171 >True <SPAN
1172 CLASS="QUOTE"
1173 >"randomness,"</SPAN
1174 > insofar as
1175 it exists at all, can only be found in certain incompletely
1176 understood natural phenomena, such as radioactive
1177 decay. Computers only <I
1178 CLASS="FIRSTTERM"
1179 >simulate</I
1180 >
1181 randomness, and computer-generated sequences of
1182 <SPAN
1183 CLASS="QUOTE"
1184 >"random"</SPAN
1185 > numbers are therefore referred to as
1186 <I
1187 CLASS="FIRSTTERM"
1188 >pseudorandom</I
1189 >.</P
1190 ></TD
1191 ></TR
1192 ><TR
1193 ><TD
1194 ALIGN="LEFT"
1195 VALIGN="TOP"
1196 WIDTH="5%"
1197 ><A
1198 NAME="FTN.AEN5857"
1199 HREF="randomvar.html#AEN5857"
1200 >[2]</A
1201 ></TD
1202 ><TD
1203 ALIGN="LEFT"
1204 VALIGN="TOP"
1205 WIDTH="95%"
1206 ><P
1207 >The <I
1208 CLASS="FIRSTTERM"
1209 >seed</I
1210 > of a
1211 computer-generated pseudorandom number series
1212 can be considered an identification label. For
1213 example, think of the pseudorandom series with a
1214 seed of <SPAN
1215 CLASS="emphasis"
1216 ><I
1217 CLASS="EMPHASIS"
1218 >23</I
1219 ></SPAN
1220 > as <TT
1221 CLASS="REPLACEABLE"
1222 ><I
1223 >Series
1224 #23</I
1225 ></TT
1226 >.</P
1227 ><P
1228 >A property of a pseurandom number series is the length of
1229 the cycle before it starts repeating itself. A good pseurandom
1230 generator will produce series with very long cycles.</P
1231 ></TD
1232 ></TR
1233 ></TABLE
1234 ><DIV
1235 CLASS="NAVFOOTER"
1236 ><HR
1237 ALIGN="LEFT"
1238 WIDTH="100%"><TABLE
1239 SUMMARY="Footer navigation table"
1240 WIDTH="100%"
1241 BORDER="0"
1242 CELLPADDING="0"
1243 CELLSPACING="0"
1244 ><TR
1245 ><TD
1246 WIDTH="33%"
1247 ALIGN="left"
1248 VALIGN="top"
1249 ><A
1250 HREF="declareref.html"
1251 ACCESSKEY="P"
1252 >Prev</A
1253 ></TD
1254 ><TD
1255 WIDTH="34%"
1256 ALIGN="center"
1257 VALIGN="top"
1258 ><A
1259 HREF="index.html"
1260 ACCESSKEY="H"
1261 >Home</A
1262 ></TD
1263 ><TD
1264 WIDTH="33%"
1265 ALIGN="right"
1266 VALIGN="top"
1267 ><A
1268 HREF="manipulatingvars.html"
1269 ACCESSKEY="N"
1270 >Next</A
1271 ></TD
1272 ></TR
1273 ><TR
1274 ><TD
1275 WIDTH="33%"
1276 ALIGN="left"
1277 VALIGN="top"
1278 >Typing variables: <B
1279 CLASS="COMMAND"
1280 >declare</B
1281 > or
1282 <B
1283 CLASS="COMMAND"
1284 >typeset</B
1285 ></TD
1286 ><TD
1287 WIDTH="34%"
1288 ALIGN="center"
1289 VALIGN="top"
1290 ><A
1291 HREF="variables2.html"
1292 ACCESSKEY="U"
1293 >Up</A
1294 ></TD
1295 ><TD
1296 WIDTH="33%"
1297 ALIGN="right"
1298 VALIGN="top"
1299 >Manipulating Variables</TD
1300 ></TR
1301 ></TABLE
1302 ></DIV
1303 ></BODY
1304 ></HTML
1305 >