help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: urandom number in Emacs


From: Emanuel Berg
Subject: Re: urandom number in Emacs
Date: Sun, 07 Nov 2021 10:28:34 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Omar Polo wrote:

> Recompiling Emacs from sources takes a couple of minutes,
> and it's a trivial function that you can write and test
> apart before including it to Emacs.

This is much better than recompiling Emacs. Why would you do
that? That's the idea with dynamic modules, then you can have
libraries in C as well as you now have them in .elc files and
use `require' one them and you compile them and only them.

> Also, I'm pretty sure that no distribution ships
> *by default* Emacs modules.

What do you mean?

> Furthermore, it's an annoyance for the users: if I want to
> use it, I have to compile it anyway, whether if it's an
> emacs built-in all I have to do is install/update Emacs via
> my package manager and I'm happy ;-)

Hm ... what Emacs do you run?

You typically get very old versions that way ... Emacs 27
seems to be in the Debian 11 repos ...

This works with Emacs 29 I think ... not sure but the
initialization should tell. Here is how I install Emacs [1]

But as for random-urandom feel free to - well, first tell me
what I should fix, then after that has been done God willing
if you want to use it wherever be my guest. Otherwise I'll
just put it on my web pile.

Hey! Is there a "CELPA" perhaps for Emacs C? Put it there <3

> you could rewrite the function to return the value via a pointer, e.g.
>
> int
> get_random_number(uint32_t *n)
> {
>       /* do stuff */
>       if (succeeded) {
>               *n = the random number;
>               return 0;
>       }
>       return -1;
> }
>
> /* later */
>
> uint32_t n;
> if (get_random_number(&n) == -1) {
>       /* Ooops */
> }

Yeah, but what then? That's just moving the situation.
The random number is returned as an emacs_value, see the
source [2] - perhaps one can send a nil emacs_value
instead of using the make_integer ...

> You should also consider why that was good for pwgen.
> If something is good for program A, it may not be "good
> enough" for program B. I don't know pwgen, but given that's
> in the first section of the manual is probably a program
> that generates a password, print it to stdout and quits.
> It doesn't have bottlenecks.

It has _randomness_, and more so than `random'.

> A program like Emacs on the other hand needs to call that
> function possibly multiple times, so investigating a bit for
> a faster way to obtain good random number is worth it IMHO.

Yeah, every history need a bit of polishing, as does every
program ...

So TODO, don't exit(1), and see if there is a speed
disadvantage compared to `random' ... what else?

[1] https://dataswamp.org/~incal/conf/.zsh/install-emacs
[2] https://dataswamp.org/~incal/emacs-init/random-urandom/random-urandom.c

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]