comp.lang.ada
 help / color / mirror / Atom feed
* what's wrong with random
@ 2002-12-22 18:03 Jan
  2002-12-22 18:38 ` Robert A Duff
  0 siblings, 1 reply; 6+ messages in thread
From: Jan @ 2002-12-22 18:03 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1232 bytes --]

Hi everybody,

I have the following problem:


BODY FROM A PACKAGE:
--------------------

      ValidChars : String :=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
                         &"0123456789!�$%&()=@+-;_#";
      subtype Int_Slice is Integer range ValidChars'Range;
      package My_Random is new Ada.Numerics.Discrete_Random
(Int_Slice);
 
   function Generate_FileName (Length : positive) return String is
      G : My_Random.Generator;
      I : Int_Slice;
      Result : String(1..Length);
   begin
      My_Random.Reset(G);

      for X in 1..Length
      loop
         I := My_Random.Random(G);
         Result(X) := Mnozina(I);
      end loop;
      return Result;
   end Generate_FileName;

-------------------

When I now test the procedure, I looks like the random number
generator in Ada changes its results too slowly, because I always get
at least 5 equal strings as result, then the result changes, and I get
again 5 equal string...

   for X in 1..10
   loop
      Put_Line(Generate_Filename(8));
   end loop;

The following code works like it should, but it's stupid, of course:

   for X in 1..10
   loop
      Put_Line(Generate_Filename(8));
      delay 0.01;
   end loop;


What's wrong?



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2002-12-23 16:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-22 18:03 what's wrong with random Jan
2002-12-22 18:38 ` Robert A Duff
2002-12-22 19:17   ` Jan
2002-12-22 20:23     ` tmoran
2002-12-22 20:56     ` Robert A Duff
2002-12-23 16:39       ` Jan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox