int r = rand(); int n = r % p; while ( a[n] != 0 ) { n = (n + n) % p; } a[n] = r; #### say (($_ + 5) % 11 ) for (0..10); 5 6 7 8 9 10 0 1 2 3 4