Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:24
erlang
2181-Use-rand-bytes-1-for-simplified-data-gener...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 2181-Use-rand-bytes-1-for-simplified-data-generation.patch of Package erlang
From 43a21905e5c6c0f89c46a1c83b1cae76828d4249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org> Date: Tue, 5 Apr 2022 12:31:00 +0200 Subject: [PATCH] Use rand:bytes/1 for simplified data generation --- erts/emulator/test/decode_packet_SUITE.erl | 6 +----- erts/emulator/test/distribution_SUITE.erl | 11 +---------- erts/emulator/test/driver_SUITE.erl | 2 +- erts/emulator/test/nif_SUITE.erl | 7 +------ erts/emulator/test/random_iolist.erl | 5 +++-- lib/stdlib/test/random_iolist.erl | 2 +- 6 files changed, 8 insertions(+), 25 deletions(-) diff --git a/erts/emulator/test/decode_packet_SUITE.erl b/erts/emulator/test/decode_packet_SUITE.erl index bedcaf3a08..891c2ec63f 100644 --- a/erts/emulator/test/decode_packet_SUITE.erl +++ b/erts/emulator/test/decode_packet_SUITE.erl @@ -174,11 +174,7 @@ pack(fcgi,Bin) -> PaddSz = rand:uniform(16) - 1, Psz = byte_size(Bin), Reserv = rand:uniform(256) - 1, - Padd = case PaddSz of - 0 -> <<>>; - _ -> list_to_binary([rand:uniform(256)-1 - || _<- lists:seq(1,PaddSz)]) - end, + Padd = rand:bytes(PaddSz), Res = <<Ver:8,Type:8,Id:16,Psz:16/big,PaddSz:8,Reserv:8,Bin/binary>>, {<<Res/binary,Padd/binary>>, Res}; pack(tpkt,Bin) -> diff --git a/erts/emulator/test/distribution_SUITE.erl b/erts/emulator/test/distribution_SUITE.erl index 4538cd870d..8fc0a2afd0 100644 --- a/erts/emulator/test/distribution_SUITE.erl +++ b/erts/emulator/test/distribution_SUITE.erl @@ -2712,15 +2712,7 @@ mk_rand_bin_list(Bytes, Binaries) -> mk_rand_bin_list(_Bytes, 0, Acc) -> Acc; mk_rand_bin_list(Bytes, Binaries, Acc) -> - mk_rand_bin_list(Bytes, Binaries-1, [mk_rand_bin(Bytes) | Acc]). - -mk_rand_bin(Bytes) -> - mk_rand_bin(Bytes, []). - -mk_rand_bin(0, Data) -> - list_to_binary(Data); -mk_rand_bin(N, Data) -> - mk_rand_bin(N-1, [rand:uniform(256) - 1 | Data]). + mk_rand_bin_list(Bytes, Binaries-1, [rand:bytes(Bytes) | Acc]). creation_selection(Config) when is_list(Config) -> register(creation_selection_test_supervisor, self()), diff --git a/erts/emulator/test/driver_SUITE.erl b/erts/emulator/test/driver_SUITE.erl index 77ef4ec6a9..902b3824f0 100644 --- a/erts/emulator/test/driver_SUITE.erl +++ b/erts/emulator/test/driver_SUITE.erl @@ -2614,7 +2614,7 @@ make_refc_binaries(Term) -> transform_bins(F, Term). build_binary(Elements) -> - list_to_binary(build_list(Elements)). + rand:bytes(Elements). build_list(Elements) -> build_list(Elements, []). diff --git a/erts/emulator/test/nif_SUITE.erl b/erts/emulator/test/nif_SUITE.erl index 55c53d3409..cb9013fc79 100644 --- a/erts/emulator/test/nif_SUITE.erl +++ b/erts/emulator/test/nif_SUITE.erl @@ -3482,12 +3482,7 @@ random_sign() -> end. random_binary() -> - list_to_binary(random_bytes(rand:uniform(32) - 1)). - -random_bytes(0) -> - []; -random_bytes(N) when N > 0 -> - [rand:uniform(256) - 1 | random_bytes(N - 1)]. + rand:bytes(rand:uniform(32) - 1). random_pid() -> Processes = erlang:processes(), diff --git a/erts/emulator/test/random_iolist.erl b/erts/emulator/test/random_iolist.erl index 555f063e0a..eb82d6a229 100644 --- a/erts/emulator/test/random_iolist.erl +++ b/erts/emulator/test/random_iolist.erl @@ -44,8 +44,8 @@ random_list(N,Acc) -> random_list(N-1,[random_byte() | Acc]). random_binary(N) -> - B = list_to_binary(random_list(N,[])), - case {rand:uniform(2),size(B)} of + B = rand:bytes(N), + case {rand:uniform(2),byte_size(B)} of {2,M} when M > 1 -> S = M-1, <<_:3,C:S/binary,_:5>> = B, @@ -53,6 +53,7 @@ random_binary(N) -> _ -> B end. + random_list(N) -> random_list(N,[]). diff --git a/lib/stdlib/test/random_iolist.erl b/lib/stdlib/test/random_iolist.erl index 6621c7ac77..ae81b6c727 100644 --- a/lib/stdlib/test/random_iolist.erl +++ b/lib/stdlib/test/random_iolist.erl @@ -40,7 +40,7 @@ random_list(N,Acc) -> random_list(N-1,[random_byte() | Acc]). random_binary(N) -> - B = list_to_binary(random_list(N,[])), + B = rand:bytes(N), case {rand:uniform(2),size(B)} of {2,M} when M > 1 -> S = M-1, -- 2.34.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor