[BUG] Set>>atRandom: is not random

Samir Saidani saidani at info.unicaen.fr
Thu Jun 26 18:05:39 UTC 2003


Here is a little piece of code to reproduce the bug: 

|s a|
s_ Set new add: 'a'; add: 'b'; yourself.
a_Random new.
i_0.
500 timesRepeat: [ ((s atRandom: a)='a') ifTrue:[ i_i+1 ]. ].
Transcript show: i; cr.

Results (~100) show that you have 1/5 to have the first element.

A workaround is to change a set as an array (probability is 1/2).

|s a|
s_ Set new add: 'a'; add: 'b'; yourself.
a_Random new.
i_0.
500 timesRepeat: [ ((s asArray atRandom: a)='a') ifTrue:[ i_i+1 ]. ].
Transcript show: i; cr.

Don't have time for the moment to fix it, but certainly due to the
"array" representation of a set (Set(1,2) appears as an array of size
5 #(nil 1 2 nil nil nil).

-- 
Samir SAIDANI				
PhD in CS / Doctorant en informatique 		web : http://www.info.unicaen.fr/~saidani
Universite de Caen - Laboratoire GREYC          tel : 02-31-56-74-30
Equipe MAD - Campus II - 14032 Caen Cedex       fax : 02-31-56-76-30



More information about the Squeak-dev mailing list