File: iterator_on_random_generator.e

package info (click to toggle)
smarteiffel 1.1-11
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 12,288 kB
  • ctags: 40,785
  • sloc: ansic: 35,791; lisp: 4,036; sh: 1,783; java: 895; ruby: 613; python: 209; makefile: 115; csh: 78; cpp: 50
file content (53 lines) | stat: -rw-r--r-- 786 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class ITERATOR_ON_RANDOM_GENERATOR

inherit ITERATOR[INTEGER];

creation make

feature

   count: INTEGER;
	 -- Of the sequence.

   item: INTEGER;

   start is
      do
	 random_generator.with_seed(seed);
	 random_generator.next;
	 left := count;
	 item := random_generator.last_integer(range);
      end;

   next is
      do
	 random_generator.next;
	 left := left - 1;
	 item := random_generator.last_integer(range);
      end;

   is_off: BOOLEAN is
      do
	 Result := left = 0;
      end;

feature {NONE}

   seed: INTEGER is 5555;

   range: INTEGER is 256;
   
   left: INTEGER;

   random_generator: MIN_STAND;

   make(c: like count) is
      require
	 count >= 0
      do
	 count := c;
	 !!random_generator.with_seed(seed);
      end;

end -- ITERATOR_ON_RANDOM_GENERATOR