Answered
This code extracts a single random page. I'm stuck and don't know what to do to make it extract 3 random pages in a file.
var NOP = this.numPages;
this.extractPages (Math.floor(Math.random()*NOP));
This code extracts a single random page. I'm stuck and don't know what to do to make it extract 3 random pages in a file.
var NOP = this.numPages;
this.extractPages (Math.floor(Math.random()*NOP));
function compareNumbers(a, b) {
// control for numeric sort
return a - b
}
// define array of pages to extract
var aPages = new Array(3);
// possible page to extract
var nPage;
// duplicated page
var bNonDup
// fill array of pages to extract
for(i = 0; i < aPages.length; i++) {
bNonDup = true;
// select a random page number
nPage = Math.floor(Math.random() * this.numPages);
// check for duplicate page in array of selected pages
for(j = 0; j < i; j++) {
if(nPage == aPages[j]) {
bNonDup = false;
}
}
// process page based on being non-duplicate page or duplicate page
if(bNonDup) {
aPages[i] = nPage; // non-duplicate page found - add page
} else {
i--; // duplicate page number - pick a different page
}
}
// sort page array into page number order
aPages.sort(compareNumbers);
// extract selected pages
for(i = 0; i < aPages.length; i++)
this.extractPages(aPages[i]);
George Kaiser