vendredi 2 avril 2021

Ada random Integer in range of array length

It's a simple question, yet I can't find anything that could help me... I want to create some random connection between graph nodes. To do this I want do two random indexes and then connect the nodes.

declare
        type randRange is range 0..100000;
        n1: randRange;
        n2: randRange;
    
        package Rand_Int is new ada.numerics.discrete_random(randRange);
        use Rand_Int;
        gen : Generator;

        begin
          n1 := random(gen) mod n; -- first node
          n2 := random(gen) mod n;

I wanted to define the range with length of my array but I got errors. Still, it doesn't compile. Also I can't perform modulo as n is natural.

75:15: "Generator" is not visible
75:15: multiple use clauses cause hiding
75:15: hidden declaration at a-nudira.ads:50, instance at line 73
75:15: hidden declaration at a-nuflra.ads:47

And I have no idea what these errors mean - obviously, something is wrong with my generator. I would appreciate if someone showed me a proper way to do this simple thing.




Aucun commentaire:

Enregistrer un commentaire