Multiple random types in one Ada program?

In my Ada program I'd like to create two types of random: a random integer in a range and a random type I defined.

In my example I have:

type servizio is (piscina, spa, entrambi);
type tempo is range 2..5;

I tried to create the random instances as follows:

package servizio_random is new Ada.Numerics.Discrete_Random(servizio);
use servizio_random;
G : Generator;


package tempo_random is new Ada.Numerics.Discrete_Random(tempo);
use tempo_random;

I'd like to use the random "servizio" in my main task, while the "tempo" random in a specific task (task type cliente (ID: cliente_id; tipo: servizio);).

Well my question is: how to do this? Do I need multiple generators or only one? I tried to put all the code in the main task but I got the error that the generator is not visible (maybe because I put two "use"). Also I tried to put the "tempo" random in the cliente task and to define there another generator (in the task's scope), but without success.

How to use function Random(G) and select which random type ("cliente" or "tempo") to use? How does this works?

Thank you.


  • Multiple generators is fine.

    But you probably want to omit the Use clauses and use qualified names, like

    G1 : servizio_random.Generator; 
    G2 : tempo_random.generator;

    then get your random data from either G1 or G2, as required.