1    /*
2    Copyright 2000 by Ralph Hartley
3    This software is licenced under the terms of the
4    Gnu Public Licence
5    */
6    import java.util.*;
7    import java.io.*;
8    import java.awt.*;
9    import javax.swing.*;
10   
11   /**A layer that decides at random if it contains an object. */
12   public class LayerProb extends Layer {
13   
14     private static final long serialVersionUID = Version.getSUID();
15   
16     /**The probability that the layer includes an object. */
17     double prob;
18   
19     /**Build a layer including an object with a given probability. */
20     LayerProb(double prob) {
21       this.prob = prob;
22       name = "%"+((int)(prob*100));
23     }
24   
25     /**Make a copy of this Layer. */
26     public Object clone() {
27       return((Object)new LayerProb(prob));
28     }
29   
30     /**Copy the value of another ProbLayer into this. */
31     public void copy(FileDefaultable thatitem) {
32       super.copy(thatitem);
33       prob = ((LayerProb)thatitem).prob;
34     }
35   
36     /** True with probability prob. 
37      *It is not guaranteed that a given object will get the
38      *same result each time. Successive calls are (nearly) independant
39      */
40     public boolean isMember(Object target) {
41       return(Math.random()<prob);
42     }
43   }
44