~ubuntu-branches/ubuntu/hardy/dbacl/hardy

« back to all changes in this revision

Viewing changes to doc/chess/randomizer.awk

  • Committer: Bazaar Package Importer
  • Author(s): Zak B. Elep
  • Date: 2006-03-26 22:35:35 UTC
  • mto: (2.1.1 etch) (1.1.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20060326223535-icwiulpkzesds4mq
ImportĀ upstreamĀ versionĀ 1.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/awk -f
 
2
{
 
3
  if( cf == 0 ) {
 
4
    cf = $2;
 
5
  }
 
6
  score[NR] = $2 - cf;
 
7
  line[NR] = $0;
 
8
}
 
9
 
 
10
END{
 
11
  # randomizer seeded by time of day
 
12
  # don't use more often than once per second.
 
13
  srand();
 
14
  while(1) {
 
15
    x = int(rand() * NR) + 1;
 
16
    t = -log(rand());
 
17
    if( log(2) * score[x] < t ) {
 
18
      print line[x];
 
19
      break;
 
20
    }
 
21
  }
 
22
}