Bug 236678 - arc4random man page example could be better
Summary: arc4random man page example could be better
Status: Closed FIXED
Alias: None
Product: Documentation
Classification: Unclassified
Component: Manual Pages (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Conrad Meyer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-21 02:22 UTC by Andras Farkas
Modified: 2019-03-21 14:45 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andras Farkas 2019-03-21 02:22:17 UTC
https://www.freebsd.org/cgi/man.cgi?query=arc4random
The example:
#define foo4random()	(arc4random() %	((unsigned)RAND_MAX + 1))
would be better as:
#define foo4random()	(arc4random_uniform((unsigned)RAND_MAX))
Comment 1 Conrad Meyer freebsd_committer freebsd_triage 2019-03-21 14:11:28 UTC
Perhaps, although there was no guarantee old rand() was uniformly distributed either?  Better to provide examples of _uniform() API use, though.
Comment 2 commit-hook freebsd_committer freebsd_triage 2019-03-21 14:45:22 UTC
A commit references this bug:

Author: cem
Date: Thu Mar 21 14:45:09 UTC 2019
New revision: 345380
URL: https://svnweb.freebsd.org/changeset/base/345380

Log:
  arc4random: Adjust example code to use uniform() API

  PR:		236678
  Reported by:	Andras Farkas <deepbluemistake AT gmail.com>

Changes:
  head/lib/libc/gen/arc4random.3