[Ada] AI12-0144 Make Discrete_Random more flexible

Message ID 20200605122338.GA56615@adacore.com
State New
Headers show
Series
  • [Ada] AI12-0144 Make Discrete_Random more flexible
Related show

Commit Message

Pierre-Marie de Rodat June 5, 2020, 12:23 p.m.
A new version of Random is provided to provide more flexibility on the
range of values returned, see the Ada AI for more details.

Tested on x86_64-pc-linux-gnu, committed on trunk

2020-06-05  Arnaud Charlet  <charlet@adacore.com>

gcc/ada/

	* libgnat/a-nudira.ads, libgnat/a-nudira.adb (Random): New
	function.

Patch

--- gcc/ada/libgnat/a-nudira.adb
+++ gcc/ada/libgnat/a-nudira.adb
@@ -56,6 +56,17 @@  is
       return Random (SRN.Generator (Gen));
    end Random;
 
+   function Random
+     (Gen   : Generator;
+      First : Result_Subtype;
+      Last  : Result_Subtype) return Result_Subtype
+   is
+      subtype Local_Subtype is Result_Subtype range First .. Last;
+      function Random is new SRN.Random_Discrete (Local_Subtype, First);
+   begin
+      return Random (SRN.Generator (Gen));
+   end Random;
+
    -----------
    -- Reset --
    -----------

--- gcc/ada/libgnat/a-nudira.ads
+++ gcc/ada/libgnat/a-nudira.ads
@@ -51,6 +51,12 @@  is
 
    function Random (Gen : Generator) return Result_Subtype;
 
+   function Random
+     (Gen   : Generator;
+      First : Result_Subtype;
+      Last  : Result_Subtype) return Result_Subtype
+     with Post => Random'Result in First .. Last;
+
    procedure Reset (Gen : Generator; Initiator : Integer);
    procedure Reset (Gen : Generator);