Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TP6
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fila2-os
TP6
Commits
fabb6073
Commit
fabb6073
authored
2 years ago
by
Théo Le Calvar
Browse files
Options
Downloads
Patches
Plain Diff
fix nextInt / nextBool crash
parent
e7957911
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Applications/SuperPong/random.cpp
+4
-25
4 additions, 25 deletions
Applications/SuperPong/random.cpp
with
4 additions
and
25 deletions
Applications/SuperPong/random.cpp
+
4
−
25
View file @
fabb6073
...
@@ -4,39 +4,18 @@
...
@@ -4,39 +4,18 @@
unsigned
long
int
Random
::
random
(
void
)
unsigned
long
int
Random
::
random
(
void
)
{
{
static
unsigned
long
int
random_seed
=
93186752
;
static
unsigned
long
int
random_seed
=
93186752
;
static
unsigned
int
a
=
1588635695
,
q
=
2
,
r
=
1117695901
;
static
unsigned
long
int
a
=
1588635695
,
q
=
2
,
r
=
1117695901
;
random_seed
=
a
*
(
random_seed
%
q
)
-
r
*
(
random_seed
/
q
);
random_seed
=
a
*
(
random_seed
%
q
)
-
r
*
(
random_seed
/
q
);
return
random_seed
;
return
random_seed
;
};
};
int
Random
::
nextInt
(
int
max
){
int
Random
::
nextInt
(
int
max
)
{
return
random
()
%
max
;
long
double
base
;
long
double
i
;
int
resultat
;
base
=
(
long
double
)
random
();
i
=
(
base
/
RAND_MAX
);
i
=
i
*
max
;
resultat
=
0
;
while
((
resultat
<
i
)
&&
(
resultat
<
max
))
{
resultat
++
;
}
return
resultat
;
};
};
bool
Random
::
nextBool
(){
bool
Random
::
nextBool
(){
return
random
()
&
1
;
unsigned
long
int
base
;
float
i
;
base
=
random
();
i
=
base
/
RAND_MAX
;
if
(
i
<
(
0.5
))
return
1
;
else
return
0
;
};
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment