From: cinap_lenrek@felloff.net
To: 9front@9front.org
Subject: Re: [9front] [PATCH] libc: replace lrand's algorithm
Date: Sat, 20 Apr 2024 14:46:12 +0200 [thread overview]
Message-ID: <A6C9292FABA651FDFD2A30B90E48801C@felloff.net> (raw)
In-Reply-To: <24YLTYTO4Q79Z.243QVQUY1V3P5@e55-lap.my.domain>
> I found (rand()<<16) + rand() in kernel's devsdp, which is
> strange considering lrand already has 32 bits of output. I
> think this should be considered a bug.
The manpage states:
Rand returns a uniform pseudo-random number x, 0≤ x <2^15.
Lrand returns a uniform long x, 0≤ x <2^31.
So lrand() only return a positive number (so really, is 31 bit
generator, not 32 bit).
Also, rand() returns only 15-bit integer. so doing rand()<<16
results in a bias as it will never set bit 15.
The lrand() implementation in the kernel is not complient
which i think is a mistake. (BUG!)
libc does not provide a function for unsigned 32-bit.
having one might be a good start.
say, lets define:
ulong ulrand(void)
in range 0<=ulrand()<2^32
and use that as the basis for all the other functions
instead of lrand().
Then as you say, constructs like rand()<<16 | rand()
should be revisited.
--
cinap
next prev parent reply other threads:[~2024-04-20 12:47 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-29 8:19 Eolien55
2024-03-29 12:39 ` qwx
2024-03-29 16:02 ` Eolien55
2024-04-01 15:47 ` qwx
2024-04-02 14:37 ` Eolien55
2024-04-02 14:52 ` Stanley Lieber
2024-04-02 20:18 ` Eolien55
2024-04-03 9:07 ` qwx
2024-04-03 19:50 ` Ori Bernstein
2024-04-03 19:54 ` Ori Bernstein
2024-04-04 21:00 ` Eolien55
2024-04-20 12:46 ` cinap_lenrek [this message]
2024-04-20 12:58 ` cinap_lenrek
2024-04-20 13:01 ` cinap_lenrek
-- strict thread matches above, loose matches on Subject: below --
2024-03-29 8:15 Eolien55
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=A6C9292FABA651FDFD2A30B90E48801C@felloff.net \
--to=cinap_lenrek@felloff.net \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).