algorithm in data mining

Pseudo code

1
2
3
4
5
6
7
8
9
10
11
12
13
for i = 1 to n
sample[i] = allNum[i]
endfor

t = n + 1

while allNum has more elements
rnd = Random([1...t])
if (rnd <= n) {
sample[rnd] = allNum[t]
}
t = t + 1
endwhile

public int[] samplingAlgorithm(int[] allNum, int sampleSize) {
int[] sample = new int[sampleSize];
for (int i = 0;i < sampleSize; i++) {
sample[i] = allNum[i];
}

int t = sampleSize + 1;
Random random = new Random();
while (t < allNum.length) {
    int rnm = random.nextInt(t);
    if (rnm < sampleSize) {
        sample[rnm] = allNum[t];
    }
    t++;
}

return sample;

}
`