<!-- Generate Indexes for Random Go Problem Selection  01/08/2001-10/06/2009 -->
<!-- ------------------------------------------------------------ 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]="TBOWK010"

// S[ 1]=1           // End of 1-st section (Break Out)

// P[ 2]="TCCTS010"

// S[ 2]=2           // End of 2-nd section (Capture Cutting Stone)

// P[ 3]="TCLNB010"
// P[ 4]="TCLHR010"
// P[ 5]="TCLHR020"
// P[ 6]="TCLKS010"
// P[ 7]="TCLKS020"
// P[ 8]="TCLSG010"

// S[ 3]=8           // End of 3-rd section (Capture to Live)

// P[ 9]="TCSTS010"

// S[ 4]=9           // End of 4-th section (Capture Stones)

// P[10]="TCNTS010"

// S[ 5]=10          // End of 5-th section (Connect Stones)

// P[11]="TMSSC010"
// P[12]="TMSSC020"
// P[13]="TMSSC030"

// 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
                  }
             }
      }

//-->

