rand() may call malloc()
The solution isn't to stop using rand(). The solution is to stop using newlib.If you're doing your own custom memory management like this, you shouldn't even have a malloc implementation at all. Even newlib is too bloated for your use case. At this point, chances are you're using a trivial subset of the C library and it'd be easy to roll your own. You can import bits and pieces from other projects (I personally sometimes copy and paste bits from PDClib for this). In such a tight embedded project, chances are you don't even have threads; why even pull in that reentrancy code?Freestanding C code with no standard library isn't scary. If you need an example, look at what we do for m1n1:https://github.com/AsahiLinux/m1n1/tree/main/srcIn particular, this is the libc subset we use (we do have malloc here, which is dlmalloc, but still not enough of libc to be worth depending on a full one):https://github.com/AsahiLinux/m1n1/tree/main/sysinc