Process to convert inputs into uniform random SDRs?

I am in need of a function which takes inputs of random type and length and outputs evenly-distributed random SDRs of configurable size and sparsity, with very low likelihood of overlap when around length 1024, sparsity 2%. Security is not a concern, only uniformity. Overlapping bits in extremely similar inputs should NOT produce output SDRs with overlap. However, the exact same input should always result in the exact same output SDR. Wondering if anyone has written something like this.

My first thought for a possible implementation would be to convert the input to string and run it through a uniform hashing function like SHA1. Then take the output hash and select random digits from the hash using a common seed, converting to 0 or 1 based on whether or not it is greater than 7, and inserting that into random positions in an SDR, using the hash as the seed, until it reaches the desired sparsity.

Is there a more elegant/ better/ faster way of achieving this? I suspect there is something obvious that is not coming to my mind right away :slight_smile:

Not sure if this is exactly what you need, but I wrote this JavaScript module to do some basic SDR operations, including getRandom(n, w). It depends on the lodash JS library.

1 Like

Hmm… I don’t think it is possible to seed the Math.random() function in Javascript, but that does give me a simpler method than what I described above.

  1. Convert input to string and run through uniform hashing function like SHA1
  2. Use hash as seed for a uniform random number generation function
  3. Follow process used in your getRandom function (generate random indexes in a loop, flipping bit to 1 up to desired sparsity)

Here is a seedable random number function for Javascript. I just did a quick look and it may be able to drop in the code.

1 Like

Ah, that looks pretty good. It takes a string as its input, so no need for the hashing function. I’d just need to verify its uniformity (don’t want similar inputs to have similar outputs).

It works really well. Thanks @jon and @rhyolight

1 Like