Array#choice on 1.8.7

Hi.

I just tested on one machine, but seems that if we make some call to
rand before using Array#choice we can have better random values, check
it out:

choice.rb

a = (1…10).to_a
3.times { puts a.choice }

[taq@~/code/ruby]ruby choice.rb
5
5
1
[taq@~/code/ruby]ruby choice.rb
9
10
2
[taq@~/code/ruby]ruby choice.rb
9
10
2

Inserting rand:

choice.rb

a = (1…10).to_a
rand
3.times { puts a.choice }

[taq@~/code/ruby]ruby choice.rb
6
8
6
[taq@~/code/ruby]ruby choice.rb
3
8
4
[taq@~/code/ruby]ruby choice.rb
6
2
10

Is there any recommendation to call rand before using choice?

Thanks.

From: Eustaquio ‘TaQ’ Rangel [mailto:[email protected]]

I just tested on one machine, but seems that if we make some call to

rand before using Array#choice we can have better random

values, check it out:

[taq@~/code/ruby]ruby choice.rb

5

5

1

what do you want, no duplicates?

kind regards -botp

Hi, I was wondering if anyone has had any luck trying to extend
CI::Reporter

Specifically, I wanted to change some formatting, so that failure
messages are enclosed in CDATA blocks. I tried extending the to_xml
method in Rakefile.rb but it seems to have no effect, so clearly I am
missing something…

My Rakefile is below. When I run it, everything happens as if I haven’t
actually extended the method at all. Ie “YO!!!” does not appear in the
XML output, and “this is broken!” never prints out. What am I missing
here?

require ‘rake’
require ‘rake/testtask’
require ‘rake/clean’
require ‘rubygems’
gem ‘ci_reporter’
require ‘ci/reporter/rake/test_unit’
require ‘ci/reporter/core’

modify ci_reporter to put failure message in CDATA element # note this

is not working class CI::Reporter::TestUnit
def to_xml(builder)
attrs = {}
each_pair {|k,v| attrs[k] = builder.trunc!(v.to_s)
unless v.nil? || v.to_s.empty?}
builder.testcase(attrs) do
failures.each do |failure|
builder.failure(:type =>
builder.trunc!(failure.name), :message =>
builder.trunc!(failure.message)) do
builder.text!(“YO!!!” +
failure.message + " (#{failure.name})\n")
builder.text!(failure.location)
end
end
end
puts “this is broken!”
end
end

task :default => [ :all_tests ]

task :all_tests => [‘ci:setup:testunit’]

Rake::TestTask.new(:all_tests) do |t|
t.test_files = FileList[‘test/*test.rb’]
t.verbose = true
t.warning = false
end

On Wed, Jun 4, 2008 at 11:01 AM, Eustaquio ‘TaQ’ Rangel
[email protected] wrote:

Peña wrote:

what do you want, no duplicates?

No, please check that the three times I run the program without rand, the
results are the same all the times. With rand before choice, on the three
times the results were different, on a more random way.

I guess you should call srand before using this (which calling rand
will do as well).
For some reason neither the new Array#shuffle nor Array#choice seems
to do this right now. Might just as well be a bug.

^ manveru

Peña wrote:

what do you want, no duplicates?

No, please check that the three times I run the program without rand,
the results are the same all the times. With rand before choice, on the
three times the results were different, on a more random way.