need to make an algorithm (formula, function) using AND OR XOR NEG SHIFT NOT etc. which calculates the element of array from an index,
the size of the element is one byte
e.g. element = index^constant
where the constant is array[index]^index
(previously calculated).
This will work only if the array size is less then 256.
How to make a byte from an index when the index would be bigger then 1 byte.

- 11
- 3
1 Answers
the same way however there will be duplicates as you got only 256 possible numbers in BYTE so if your array is bigger than 256 there must be duplicates.
to avoid obvious mirroring you can not use monotonic functions for example
value[ix] = ix
is monotnic so it will be saw like shape mirroring the content of array every 256 bytes. To avoiding this you need to combine more stuff together. Its similar to computing own pseudo random generator. The usual approaches are:
modular arithmetics
something like:
value[ix]=( ( c0*ix + c1*ix*ix + c2*ix*ix*ix )%prime )&255
if constants
c0,c1,c2
andprime
are big enough the output looks random so there will be much less repeated patterns visible in the output ... But you need to use arithmetic of bitwidth that can hold the prime ...In case you are hitting the upper bounds of your arithmetics bitwidth then you need to use
modmul,modpow
to avoid overflows. See:swapping bits
simply do some math on your
ix
where you also use ix with swapped bits. That will change the monotonic properties a lot... This approach works best however on cumulative sub-result which is not the case of yours. I would try:value[ix]=( ix + ((ix<<3)*5) - ((ix>>2)*7) + ((3*ix)^((ix<<4)||(ix>>4))) )&255
playing with constants and operators achieve different results. However with this approach you need to check validity (which I did not!). So render graph for first few values (like 1024) where
x
axis isix
andy
axis isvalue[ix]
. There you should see if the stuff is repeating or even saturated towards some value and if it is change the equation.for more info see How to seed to generate random numbers?
Of coarse after all this its not possible to get the ix
from value[ix]
...

- 49,595
- 11
- 110
- 380
-
I've made it different way, wanted to answer but can't here )) just this way: elment = index^constant same as before but constant is array[index]^index^(index>>8)^(index>>16)^(ind.... – Natascha Koschkina Dec 03 '19 at 09:27
-
@NataschaKoschkina yep the idea is the same ... but yours need to have big range of `index` so the `index>>8` and `index>>16` will not turn to zero. You can combine any math/logic operations together ... – Spektre Dec 03 '19 at 20:57