diff options
Diffstat (limited to '03-switch3.rb')
-rw-r--r-- | 03-switch3.rb | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/03-switch3.rb b/03-switch3.rb index 7cbdc2f..f8809d7 100644 --- a/03-switch3.rb +++ b/03-switch3.rb @@ -33,25 +33,22 @@ $levels << Level.new do end def generate - frames = {} - @interfaces.each do |iface| - next if rand < 0.3 + iface = interfaces.sample - if rand < 0.4 || @fib[iface].nil? - src = Frame2.gen_addr - @next_fib[iface] = src - else - src = @fib[iface] - end + if rand < 0.4 || @fib[iface].nil? + src = Frame2.gen_addr + @next_fib[iface] = src + else + src = @fib[iface] + end - dst = nil - dst = (@fib.values.compact - [src]).sample if rand < 0.5 - dst = Frame2.gen_addr if dst.nil? + dst = nil + dst = (@fib.values.compact - [src]).sample if rand < 0.5 + dst = Frame2.gen_addr if dst.nil? - frames[@count.to_s] = Frame2.new(iface, src, dst) - @count += 1 - end - frames + frame = Frame2.new(iface, src, dst) + @count += 1 + frame end def click |