mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 01:51:03 +09:00
Welcome: Replace rand()/srand() with AK::get_random_uniform()
This commit is contained in:
parent
02121336b4
commit
902d24136b
Notes:
sideshowbarker
2024-07-18 04:55:16 +09:00
Author: https://github.com/thankyouverycool
Commit: 902d24136b
Pull-request: https://github.com/SerenityOS/serenity/pull/9736
1 changed files with 3 additions and 8 deletions
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "WelcomeWidget.h"
|
#include "WelcomeWidget.h"
|
||||||
|
#include <AK/Random.h>
|
||||||
#include <Applications/Welcome/WelcomeWindowGML.h>
|
#include <Applications/Welcome/WelcomeWindowGML.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibCore/Process.h>
|
#include <LibCore/Process.h>
|
||||||
|
@ -17,7 +18,6 @@
|
||||||
#include <LibMarkdown/Document.h>
|
#include <LibMarkdown/Document.h>
|
||||||
#include <LibWeb/OutOfProcessWebView.h>
|
#include <LibWeb/OutOfProcessWebView.h>
|
||||||
#include <serenity.h>
|
#include <serenity.h>
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
WelcomeWidget::WelcomeWidget()
|
WelcomeWidget::WelcomeWidget()
|
||||||
{
|
{
|
||||||
|
@ -68,7 +68,6 @@ WelcomeWidget::WelcomeWidget()
|
||||||
|
|
||||||
open_and_parse_readme_file();
|
open_and_parse_readme_file();
|
||||||
open_and_parse_tips_file();
|
open_and_parse_tips_file();
|
||||||
srand(time(nullptr));
|
|
||||||
set_random_tip();
|
set_random_tip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,12 +115,8 @@ void WelcomeWidget::set_random_tip()
|
||||||
if (m_tips.is_empty())
|
if (m_tips.is_empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
size_t n;
|
m_initial_tip_index = get_random_uniform(m_tips.size());
|
||||||
do
|
m_tip_label->set_text(m_tips[m_initial_tip_index]);
|
||||||
n = rand();
|
|
||||||
while (n >= m_tips.size());
|
|
||||||
m_initial_tip_index = n;
|
|
||||||
m_tip_label->set_text(m_tips[n]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WelcomeWidget::paint_event(GUI::PaintEvent& event)
|
void WelcomeWidget::paint_event(GUI::PaintEvent& event)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue