Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ada: Seeding Random

Tags:

random

ada

How can I seed Ada.Numerics.Discrete_Random with a 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 seeds the "Rand_Int" with the "seed" value, but I cannot find any instruction on actually setting the seed value. Or I am completely looking at this the wrong way? I want to set the seed value to a number (like 4 or 5) that I can control to observe test results.

Thanks!

like image 629
SquidsEnMasse Avatar asked Dec 28 '25 15:12

SquidsEnMasse


1 Answers

Pass a second Integer argument to Reset. Here it's initiator.

Rand_Int.Reset(seed, initiator);

Ada is one of the few languages with complete, detailed reference manual and rationale available free of charge. Use it! Additionally, here is the more recent Ada version's standard.

Another note: the variable name seed in your code is a terrible choice. A choice like state or generator would be much better.

NB: Ada is really a very nice language in many respects. People gripe about the very strong, detailed type system. Then when the system's done and it runs first try with few bugs, they mysteriously forget to attribute it to Ada. The significant down sides are library availability and maturity of IDEs.

like image 124
Gene Avatar answered Dec 31 '25 05:12

Gene



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!