mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
Userland: Migrate from arc4random_uniform() to get_random_uniform()
This commit is contained in:
parent
069bf988ed
commit
5a0468c21f
Notes:
sideshowbarker
2024-07-18 18:08:55 +09:00
Author: https://github.com/boricj Commit: https://github.com/SerenityOS/serenity/commit/5a0468c21f6 Pull-request: https://github.com/SerenityOS/serenity/pull/7105
5 changed files with 11 additions and 6 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/Format.h>
|
||||
#include <AK/Random.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/Vector.h>
|
||||
|
@ -80,7 +81,7 @@ static void do_systematic_tests()
|
|||
static void randomize_from(size_t* buffer, size_t len, const Vector<size_t>& values)
|
||||
{
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
buffer[i] = values[arc4random_uniform(values.size())];
|
||||
buffer[i] = values[get_random_uniform(values.size())];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,7 +140,7 @@ static void do_random_tests()
|
|||
}
|
||||
for (size_t i = 0; i < fuzz_syscall_count; ++i) {
|
||||
// Construct a nice syscall:
|
||||
int syscall_fn = arc4random_uniform(Syscall::Function::__Count);
|
||||
int syscall_fn = get_random_uniform(Syscall::Function::__Count);
|
||||
randomize_from(direct_sc_args, array_size(direct_sc_args), interesting_values);
|
||||
randomize_from(fake_sc_params, fake_params_count, interesting_values);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
#include "DNSName.h"
|
||||
#include <AK/Random.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
@ -64,7 +65,7 @@ void DNSName::randomize_case()
|
|||
for (char c : m_name) {
|
||||
// Randomize the 0x20 bit in every ASCII character.
|
||||
if (isalpha(c)) {
|
||||
if (arc4random_uniform(2))
|
||||
if (get_random_uniform(2))
|
||||
c |= 0x20;
|
||||
else
|
||||
c &= ~0x20;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/Debug.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/Random.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibCore/ConfigFile.h>
|
||||
|
@ -194,7 +195,7 @@ Vector<DNSAnswer> LookupServer::lookup(const DNSName& name, const String& namese
|
|||
{
|
||||
DNSPacket request;
|
||||
request.set_is_query();
|
||||
request.set_id(arc4random_uniform(UINT16_MAX));
|
||||
request.set_id(get_random_uniform(UINT16_MAX));
|
||||
DNSName name_in_question = name;
|
||||
if (should_randomize_case == ShouldRandomizeCase::Yes)
|
||||
name_in_question.randomize_case();
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <AK/JsonObject.h>
|
||||
#include <AK/JsonValue.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/Random.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/DateTime.h>
|
||||
|
@ -115,7 +116,7 @@ int main(int argc, char** argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
u32 i = arc4random_uniform(quotes.size());
|
||||
u32 i = get_random_uniform(quotes.size());
|
||||
const auto& chosen_quote = quotes[i];
|
||||
auto datetime = Core::DateTime::from_timestamp(chosen_quote.utc_time());
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Random.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <errno.h>
|
||||
|
@ -38,7 +39,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
|||
// Fisher-Yates shuffle
|
||||
String tmp;
|
||||
for (size_t i = lines.size() - 1; i >= 1; --i) {
|
||||
size_t j = arc4random_uniform(i + 1);
|
||||
size_t j = get_random_uniform(i + 1);
|
||||
// Swap i and j
|
||||
if (i == j)
|
||||
continue;
|
||||
|
|
Loading…
Reference in a new issue