Name: Anonymous 2012-01-08 21:14
Need to sort 10 randomly generated numbers with arrays and bubble sorting. I've figured out how to get the sorting, but how do I randomize the numbers?
let A be an array with indeces ranging from 1 to n
for i from 1 to n
let j be a random index with i < j <= n
swap(A[i], A[j])
from random import randrange
array = []
for i in range(0,9):
array.append(randrange(5000))
array.sort()
print array
int[] listInts = new int[10];
Random r = new Random();
for (int i = 0; i < 10; i++)
listInts[i] = r.Next(5000);
A[⍋A←10?5000]
for n in {0..9}; do printf "$RANDOM\n" done | sort -n