Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
emacs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
emacs
emacs
Commits
d16ae622
Commit
d16ae622
authored
Mar 19, 2014
by
Paul Eggert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* fns.c (Frandom): Fix rare bug where the result isn't random.
parent
37ca9077
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
2 deletions
+13
-2
src/ChangeLog
src/ChangeLog
+2
-0
src/fns.c
src/fns.c
+11
-2
No files found.
src/ChangeLog
View file @
d16ae622
2014-03-19 Paul Eggert <eggert@cs.ucla.edu>
* fns.c (Frandom): Fix rare bug where the result isn't random.
Fix porting inconsistency about rounding to even.
* floatfns.c (emacs_rint) [!HAVE_RINT]: Round to even.
This way, the unusual !HAVE_RINT case acts like the usual
...
...
src/fns.c
View file @
d16ae622
...
...
@@ -79,8 +79,17 @@ See Info node `(elisp)Random Numbers' for more details. */)
seed_random
(
SSDATA
(
limit
),
SBYTES
(
limit
));
val
=
get_random
();
if
(
NATNUMP
(
limit
)
&&
XFASTINT
(
limit
)
!=
0
)
val
%=
XFASTINT
(
limit
);
if
(
INTEGERP
(
limit
)
&&
0
<
XINT
(
limit
))
while
(
true
)
{
/* Return the remainder, except reject the rare case where
get_random returns a number so close to INTMASK that the
remainder isn't random. */
EMACS_INT
remainder
=
val
%
XINT
(
limit
);
if
(
val
-
remainder
<=
INTMASK
-
XINT
(
limit
)
+
1
)
return
make_number
(
remainder
);
val
=
get_random
();
}
return
make_number
(
val
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment