I'm trying to generate a list of random ints/floats, within a certain range, as fast as possible, eg `generate_x_ints(amount: u32, range: [u32; 2]) -> Vec' (doesn't necessarily have to be a vec). It generates a list with a length of 'amount' filled with numbers inclusively between the min/max of the range given.
My requirements are that it should be uniformly random, and very fast. It doesnt need to be ' secure'. I don't want to involve C or assembly, and it needs to run on linux/windows/mac. I am totally okay with using unsafe for this, given it's a very isolated/disconnected part of my application, and it will mostly just be used in nodejs. I'm using it for a game, and in particular I care about these quantities: 10, 1000, 1,000,000, 10,000,000 and 100,000,000. I'm happy to use more ram for speed improvements.
It's very easy to iterate from 0..max
and add a random number to the list, but i'm looking for better optimised ways for my use case. Because i know exactly how many I want, and exactly what range i want, and im not generating them sporadically on demand, im sure it can be optimised for that.
What I want help generally with is suggestions for how to best optimise for my use case for maximum speed. Possibilities i've explored are: SIMD, "fill", splitting random numbers into multiple random numbers (eg if i need 100 numbers between 1 and 5, generating a single u32 can maybe be wasteful if im only using it for that?), and finally threading (which id rather apply if necessary after it's been optimised).
A more specific question I have is how can I use the fill method in rand (or other alternatives) to generate a bunch of random numbers at once, but that are in a given range - without screwing with the uniformity and such.
Here is my benchmarking code: GitHub - gc/rust-rng-benchmarking