File 1401-io_proto_SUITE-Use-rand-instead-of-random.patch of Package erlang
From eb7e620b4628d8c670b623cc5ee3e2909feb22f9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Mon, 21 Mar 2022 06:44:17 +0100
Subject: [PATCH 1/2] io_proto_SUITE: Use rand instead of random
---
lib/stdlib/test/io_proto_SUITE.erl | 41 ++++++++++++++++++------------
1 file changed, 25 insertions(+), 16 deletions(-)
diff --git a/lib/stdlib/test/io_proto_SUITE.erl b/lib/stdlib/test/io_proto_SUITE.erl
index 52ed5c608f..525b479fef 100644
--- a/lib/stdlib/test/io_proto_SUITE.erl
+++ b/lib/stdlib/test/io_proto_SUITE.erl
@@ -460,7 +460,8 @@ unicode_options(Config) when is_list(Config) ->
%% Tests various unicode options on random generated files.
unicode_options_gen(Config) when is_list(Config) ->
ct:timetrap({minutes,30}), %% valgrind needs a alot of time
- random:seed(1240, 900586, 553728),
+ rand:seed(default),
+ io:format("*** SEED: ~p ***\n", [rand:export_seed()]),
PrivDir = proplists:get_value(priv_dir, Config),
AllModes = [utf8,utf16,{utf16,big},{utf16,little},
utf32,{utf32,big},{utf32,little}],
@@ -513,12 +514,11 @@ unicode_options_gen(Config) when is_list(Config) ->
[read,read_ahead,{encoding,Encoding}],
Read4),
- Ulist2 = [X || X <- Ulist, X =/= $\n, X =/= $\s],
- Ulist3 = [X || X <- Ulist, X =/= $\n],
+ Ulist2 = [X || X <- Ulist, X =/= $\n, X =/= $\s, X =/= $\t],
Ulist = done(Res1),
Ulist = done(Res2),
Ulist2 = done(Res3),
- Ulist3 = done(Res4),
+ Ulist2 = done(Res4),
file:delete(Fname)
end,
@@ -635,22 +635,31 @@ enc2str({A1,A2}) when is_atom(A1), is_atom(A2) ->
random_unicode(0) ->
- [];
+ %% io:fread(Device, Promp, "~ts") will return an error if the file
+ %% ends with whitespace characters. This behavior seems to be
+ %% deliberate. Therefore, be sure that we never end the file with
+ %% a sequence of whitespace characters.
+ [$! + rand:uniform(64) |
+ case rand:uniform(20) of
+ A when A =< 1 -> [$\n];
+ _ -> []
+ end];
random_unicode(N) ->
- %% Favour large unicode and make linebreaks
- X = case random:uniform(20) of
+ %% Favor large unicode code points and make line breaks.
+ X = case rand:uniform(20) of
A when A =< 1 -> $\n;
- A0 when A0 =< 3 -> random:uniform(16#10FFFF);
- A1 when A1 =< 6 -> random:uniform(16#10FFFF - 16#7F) + 16#7F;
- A2 when A2 =< 12 -> random:uniform(16#10FFFF - 16#7FF) + 16#7FF;
- _ -> random:uniform(16#10FFFF - 16#FFFF) + 16#FFFF
+ A when A =< 3 -> rand:uniform(16#10FFFF);
+ A when A =< 6 -> rand:uniform(16#10FFFF - 16#7F) + 16#7F;
+ A when A =< 12 -> rand:uniform(16#10FFFF - 16#7FF) + 16#7FF;
+ _ -> rand:uniform(16#10FFFF - 16#FFFF) + 16#FFFF
end,
- case X of
- Inv1 when Inv1 >= 16#D800, Inv1 =< 16#DFFF;
- Inv1 =:= 16#FFFE;
- Inv1 =:= 16#FFFF ->
+ if
+ X =:= $\r; %Can be eaten by io:get_line/2.
+ 16#D800 =< X, X =< 16#DFFF;
+ X =:= 16#FFFE;
+ X =:= 16#FFFF ->
random_unicode(N);
- _ ->
+ true ->
[X | random_unicode(N-1)]
end.
--
2.34.1