I want to generate binaries, where the average hamming distance between the items is 50%. The second condition is that the distance should not fall below 40% or go above 60%. Another complication is that the items are not generated in sequence, but once in a while and I don't want to loop over all of the items to check and regenerate, because it will become a slow process after a while.
Is there a mechanism or algorithm to achieve this ?
Currently I use the following code :
def rand(size):
op = np.random.uniform()
return np.random.choice([0,1], size=size, p=[op, 1-op] )
but it breaks even when I generate 10 items f.e. (hamming dist) :
[ [ 0 2510 8209 4305 3896 1619 7231 6356 8103 3265]
[2510 0 8131 4347 3940 1697 7219 6334 8037 3305]
[8209 8131 0 5858 6449 9312 2100 3317 1030 7196]
[4305 4347 5858 0 4661 4088 5598 5311 5764 4590]
[3896 3940 6449 4661 0 3485 6093 5650 6385 4251]
[1619 1697 9312 4088 3485 0 8034 6739 9152 2716]
[7231 7219 2100 5598 6093 8034 0 3831 2238 6510]
[6356 6334 3317 5311 5650 6739 3831 0 3405 5933]
[8103 8037 1030 5764 6385 9152 2238 3405 0 7112]
[3265 3305 7196 4590 4251 2716 6510 5933 7112 0]]
min: 1030 Avg distance : 0.470624%
btw. binaries are 10 000 bits.
Aucun commentaire:
Enregistrer un commentaire