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
|
# global_array_test.kbs - j.m.reneau 2012-10-07
dim a(100)
global a
for t = 0 to a[?]-1
a[t] = t
next t
print total_a()
call print_a(10)
call shuffle_a
print total_a()
call print_a(10)
function total_a()
total_a = 0
for b = 0 to a[?]-1
total_a = total_a + a[b]
next b
end function
subroutine print_a(n)
# print first n elements of a
for t = 0 to n-1
if t <> 0 then print " ";
print a[t];
next t
print
end subroutine
subroutine shuffle_a()
# shuffle the elements in a
# swap enough random paris to mix it up real good
for t = 1 to a[?] * 10
i = int(rand*a[?])
j = int(rand*a[?])
q = a[j]
a[j] = a[i]
a[i] = q
next t
end subroutine
|