PageRenderTime 4ms CodeModel.GetById 2ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/iterator/iterator_on_random_generator.e

http://github.com/tybor/Liberty
Specman e | 52 lines | 38 code | 13 blank | 1 comment | 0 complexity | a3e42fa64823c523310058cac93a4650 MD5 | raw file
 1class ITERATOR_ON_RANDOM_GENERATOR
 2
 3inherit
 4	ITERATOR[INTEGER]
 5
 6creation {ANY}
 7	make
 8
 9feature {ANY}
10	count: INTEGER
11			-- Of the sequence.
12
13	item: INTEGER
14
15	start is
16		do
17			random_number_generator.with_seed(seed)
18			random_number_generator.next
19			left := count
20			item := random_number_generator.last_integer(range)
21		end
22
23	next is
24		do
25			random_number_generator.next
26			left := left - 1
27			item := random_number_generator.last_integer(range)
28		end
29
30	is_off: BOOLEAN is
31		do
32			Result := left = 0
33		end
34
35feature {}
36	seed: INTEGER is 5555
37
38	range: INTEGER is 256
39
40	left: INTEGER
41
42	random_number_generator: MINIMAL_RANDOM_NUMBER_GENERATOR
43
44	make (c: like count) is
45		require
46			count >= 0
47		do
48			count := c
49			create random_number_generator.with_seed(seed)
50		end
51
52end -- class ITERATOR_ON_RANDOM_GENERATOR