<!-- Generate Indexes for Random Go Problem Selection 01/08/2001-01/24/2001 --> <!-- ------------------------------------------------------------ 01/24/2001 --> <!-- www.davar.net/GO/PROBLEMS/RANDPROB.JS --> <!-- Copyright (C) 2001 by Vladimir Veytsel --> <!-- // RANDPROB is a code insert that is used to generate random indexes for // selection of problem names from sectioned problem list. // Code presumes that the array of problem names is declared and initialized. // The variables that split problem list into sections should have their // values assigned as in the example below: // P=new Array(14) // Problem array (starts from "0") // S=new Array( 7) // Section array (starts from "0") // S[ 0]=0 // Used for uniform treatment of section ranges // P[ 1]="TSJBOW01" // S[ 1]=1 // End of 1-st section (Break Out) // P[ 2]="TSJCCT01" // S[ 2]=2 // End of 2-nd section (Capture Cutting Stone) // P[ 3]="TSJCLB01" // P[ 4]="TSJCLH01" // P[ 5]="TSJCLH02" // P[ 6]="TSJCLK01" // P[ 7]="TSJCLK02" // P[ 8]="TSJCLS01" // S[ 3]=8 // End of 3-rd section (Capture to Live) // P[ 9]="TSJCST01" // S[ 4]=9 // End of 4-th section (Capture Stones) // P[10]="TSJCNT01" // S[ 5]=10 // End of 5-th section (Connect Stones) // P[11]="TSJMSS01" // P[12]="TSJMSS02" // P[13]="TSJMSS03" // As a result of the execution of the code below the random indexes will be // generated to be used within HTML text for random problem selection (using // "document.write"): // i[0] Random index within entire list that differs from all section indexes // i[n] Random index within n-th section // Warning: If the total number of problems in the problem list is equal // to the number of sections, index "i[0]" will be equal to one // of the section indexes. i=new Array(S.length) // Index array (starts from "0") S[S.length-1]=P.length-1 // End of last section Total=P.length-1 i[0]=Math.floor(Math.random()*Total)%Total+1 for (n=1;n<S.length;n++) i[n]=(i[0]%(S[n]-S[n-1]))+S[n-1]+1 // Random index within n-th section // Random index within the entire list (differs from all section indexes) if (Total>S.length-1) // Prevent infinite cycle {Valid=false // Index valid flag while (!Valid) // Repeat until valid index is generated {i[0]=Math.floor(Math.random()*Total)%Total+1 for (n=1;n<S.length;n++) {Valid=(i[0]!=i[n]) if (!Valid) break } } } //-->