I previously raised this issue in an issue, but I think that isn’t the best forum for discussion, so let’s discuss the rand issue here instead.
To summarize that issue: I asked Gemini to look at matrix_ops.c and suggest improvement, and it noted several issues with the use of rand:
- The random numbers are weak
randis not thread-safe, so if we are multi-threaded we need locks.- In the
power_iterationloop, it can lead to an infinite retry if the randomly chosen vector is not random enough and winds up collinear with all previous vectors.
Of these, only #2 seems like a significant issue. Unfortunately, rand_r (which is thread-safe) is not portable. Gemini suggested some xorshift algorithm that seemed overly simple and of unclear provenance.
In further searches I found https://github.com/imneme/pcg-c-basic, which is an Apache-licensed small C implementation of one of a class of interesting generators called PCG. (It’s a C excerpt/distillation of a C++ library which is available in Ubuntu as libpcg-cpp-dev.) Theres more discussion of the project here, https://www.pcg-random.org/, and the “k-dimensional equidistribution” sounds like an interesting property which addresses #3 as well, but that might not be covered by the simple C version.
I doubt this problem is worth resolving today, but it does raise questions which may arise in more important cases:
- What is the process to consider adding a new library dependence to graphviz?
- Would including file from an Apache-licensed C project in graphviz ok, or is that not allowed by the licensing?
-Brian