3
votes

Working on a little game for the BBC Microbit.

with Ada.Numerics.Discrete_Random reports "Ada.Numerics" is not a predefined library unit.

Does Ada provide another way to generate random numbers on the BBC MicroBit? arch/ARM/Nordic/svd/nrf51/nrf51_svd-rng defines a random number generator record RNG_Peripheral. Is this what I'm searching for or only used with Bluetooth?

GPS 2018 (20180528) hosted on x86_64-pc-linux-gnu
GNAT Community 2018 (20180524-73)

Active toolchain: arm-eabi

the GNAT Programming Studio

(c) 2001-2018 AdaCore

My code:

with Ada.Numerics.Discrete_Random;

package body Flip_A_Coin is

   package Random_Coin is new Ada.Numerics.Discrete_Random(Coin);

   G: Random_Coin.Generator;

   ------------------
   --  Reset       --
   ------------------

   procedure Reset is

   begin

      Random_Coin.Reset(G);

   end Reset;

   ------------------
   --  Flip        --
   ------------------

   function Flip
     return Coin is

   begin

      return Random_Coin.Random(G);

   end Flip;

begin

   Reset;

end Flip_A_Coin;
3
You named a variable G ??!!Mawg says reinstate Monica

3 Answers

4
votes

If you build using

for Runtime ("ada") use "ravenscar-full-microbit";

in your project or

--RTS=ravenscar-full-microbit

on the command line you will find the standard Ada RNGs.

You could also try, as you suggest, using the NRF51_SVD.RNG from the Ada Drivers Library, which should do the trick.

1
votes

If you have floating-point numbers available, you can use U_Rand available @ Mathpaqs.

1
votes

There are a number of RNGs available in the PragmAda Reusable Components. Maybe one of them will suit you.

PragmARCs