Skip to content

Commit a4c6746

Browse files
committed
Merge branch 'topic/csprng' into 'master'
Use GNATCOLL.Random instead of Ada.Numerics.Discrete_Random See merge request eng/toolchain/aws!41
2 parents 5314354 + 7cd7261 commit a4c6746

File tree

2 files changed

+6
-70
lines changed

2 files changed

+6
-70
lines changed

src/core/aws-utils.adb

Lines changed: 6 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ pragma Ada_2012;
3131

3232
with Ada.Calendar.Time_Zones;
3333
with Ada.Integer_Text_IO;
34-
with Ada.Numerics.Discrete_Random;
3534
with Ada.Numerics.Long_Elementary_Functions;
3635
with Ada.Streams.Stream_IO;
3736
with Ada.Strings.Fixed;
3837
with Ada.Strings.Maps.Constants;
3938
with Ada.Text_IO;
4039

40+
with GNATCOLL.Random;
41+
4142
pragma Warnings (Off);
4243
with Ada.Strings.Unbounded.Aux;
4344
pragma Warnings (On);
@@ -50,7 +51,8 @@ package body AWS.Utils is
5051

5152
use type Ada.Directories.File_Kind;
5253

53-
package Integer_Random is new Numerics.Discrete_Random (Random_Integer);
54+
function Integer_Random is new
55+
GNATCOLL.Random.Random_Range (Random_Integer);
5456

5557
function Local_To_GMT (DT : Calendar.Time) return Calendar.Time
5658
with Inline;
@@ -67,14 +69,6 @@ package body AWS.Utils is
6769
-- Returns True if the string pointed to by Str and terminating to Last
6870
-- is well-formed UTF-8.
6971

70-
protected Shared_Random is
71-
function Generate return Random_Integer;
72-
procedure Reset;
73-
procedure Reset (Seed : Integer);
74-
private
75-
Random_Generator : Integer_Random.Generator;
76-
end Shared_Random;
77-
7872
---------------------
7973
-- Append_With_Sep --
8074
---------------------
@@ -1004,35 +998,16 @@ package body AWS.Utils is
1004998

1005999
function Random return Random_Integer is
10061000
begin
1007-
return Shared_Random.Generate;
1001+
return Integer_Random;
10081002
end Random;
10091003

1010-
------------------
1011-
-- Random_Reset --
1012-
------------------
1013-
1014-
procedure Random_Reset (Seed : Integer) is
1015-
begin
1016-
Shared_Random.Reset (Seed);
1017-
end Random_Reset;
1018-
10191004
-------------------
10201005
-- Random_String --
10211006
-------------------
10221007

10231008
procedure Random_String (Item : out String) is
1024-
Chars : constant String
1025-
:= "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
1026-
Rand : Random_Integer := 0;
10271009
begin
1028-
for Elem of Item loop
1029-
if Rand = 0 then
1030-
Rand := Random;
1031-
end if;
1032-
1033-
Elem := Chars (Integer (Rand rem Chars'Length) + 1);
1034-
Rand := Rand / Chars'Length;
1035-
end loop;
1010+
GNATCOLL.Random.Random_Alphanumerical_String (Item);
10361011
end Random_String;
10371012

10381013
function Random_String (Length : Natural) return String is
@@ -1131,37 +1106,6 @@ package body AWS.Utils is
11311106

11321107
end Semaphore;
11331108

1134-
-------------------
1135-
-- Shared_Random --
1136-
-------------------
1137-
1138-
protected body Shared_Random is
1139-
1140-
--------------
1141-
-- Generate --
1142-
--------------
1143-
1144-
function Generate return Random_Integer is
1145-
begin
1146-
return Integer_Random.Random (Random_Generator);
1147-
end Generate;
1148-
1149-
-----------
1150-
-- Reset --
1151-
-----------
1152-
1153-
procedure Reset is
1154-
begin
1155-
Integer_Random.Reset (Random_Generator);
1156-
end Reset;
1157-
1158-
procedure Reset (Seed : Integer) is
1159-
begin
1160-
Integer_Random.Reset (Random_Generator, Seed);
1161-
end Reset;
1162-
1163-
end Shared_Random;
1164-
11651109
-----------------------
11661110
-- Significant_Image --
11671111
-----------------------
@@ -1317,6 +1261,4 @@ package body AWS.Utils is
13171261
end if;
13181262
end Time_Zone;
13191263

1320-
begin
1321-
Shared_Random.Reset;
13221264
end AWS.Utils;

src/core/aws-utils.ads

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,6 @@ package AWS.Utils is
9595
=> C in '0' .. '9' | 'a' .. 'z' | 'A' .. 'Z');
9696
-- Returns random string
9797

98-
procedure Random_Reset (Seed : Integer);
99-
-- This function is needed only if the user wants to get predictable random
100-
-- numbers. It means that after calling Random_Reset with the same Seed the
101-
-- same sequence of Random and Random_String calls will give the same
102-
-- results.
103-
10498
function Image (N : Natural) return String with
10599
Post => Image'Result'Length > 0
106100
and then Image'Result (Image'Result'First) /= ' ';

0 commit comments

Comments
 (0)