class POINTS_IN_CIRCLE creation go feature go is local x, y, r, theta : REAL i, count : INTEGER rand : STD_RAND pair : GBN_KEYED_PAIR [REAL, REAL] heap : GBN_HEAP [ GBN_KEYED_PAIR [REAL, REAL] ] mc : MATH_CONSTANTS twopi : REAL time : MICROSECOND_TIME do -- this part is the nasty part if (argument_count /= 1 and argument_count /= 2) or else (not argument(1).is_integer) then std_error.put_string(argument(0) + " expects args: count and optional seed or non-integer (clock seed)%N") else count := argument(1).to_integer if argument_count = 2 then if argument(2).is_integer then !! rand . with_seed ( argument(2).to_integer ) else time.update !! rand . with_seed ( time.microsecond ) end else !! rand . make end -- this part is the nice part !! heap . make twopi := ( 2 * mc.Pi).to_real from i := 1 until i > count loop rand . next r := rand . last_real . sqrt . to_real rand . next theta := rand . last_real theta := theta * twopi x := 0.5 + 0.5 * r * ( theta.cos.to_real ) y := 0.5 + 0.5 * r * ( theta.sin.to_real ) !! pair . make ( x ) pair . put ( y ) heap . add ( pair, Void ) i := i + 1 end from io . put_integer ( heap.count ) io . put_new_line until heap . is_empty loop pair := heap . min io . put_real ( pair . key ) io . put_character (' ') io . put_real ( pair . item ) io . put_new_line heap . delete_min end end -- if valid arguments end -- routine go end -- class POINTS_IN_CIRCLE