Hell: Random Landing

How can I seed Ada.Numerics.Discrete_Random with discrete value? I see code like:

declare
   type Rand_Range is range 25..75;
   package Rand_Int is new Ada.Numerics.Discrete_Random(Rand_Range);
   seed : Rand_Int.Generator;
   Num : Rand_Range;
begin
   Rand_Int.Reset(seed);
   Num := Rand_Int.Random(seed);
   Put_Line(Rand_Range'Image(Num));
end;

      

which seed "Rand_Int" is "seed", but I can't find any instruction on actually determining the seed. Or am I completely looking at this the wrong way? I want to set an initial value to a number (like 4 or 5) that I can control to observe the test results.

Thank!

+2


source to share


1 answer


Pass the second argument Integer

to Reset

. Here he is initiator

.

Rand_Int.Reset(seed, initiator);

      

Ada is one of the few languages ​​with a complete, detailed reference guide and rationale available for free . Use it! Also, here is the more recent Ada version standard .



Another side note: a variable name seed

in your code is a terrible choice. A choice like state

or generator

would be much better.

NB: Ada is a very good language in many ways. People are faced with a very strong, detailed type system. Then when the system is running and it starts up first, try with a few errors, they mysteriously forget to attribute it to Ada. The significant aspects are the availability and maturity of the IDE library.

+6


source







All Articles