giggetto71 Active Member Licensed User Longtime User Jul 12, 2021 #1 Hi need some guidance here. I am developing a Zobrist hashing algorithm (https://en.wikipedia.org/wiki/Zobrist_hashing). for the implementation, one needs to generate a series of random numbers and then XOR them. one can use 32 bits to generate the random numbers but it would be much better to be able to use use 64 bit. a conceptual simplified idea (the actual alg needs 64 random numbers and then they are XORed is: B4X: Copy Dim MaxInt As Int,rndint As Int,key As Int, ii As Int MaxInt = Power(2,31) For ii = 0 To 63 rndint = Rnd(0,MaxInt) key=Bit.Xor(key,rndint) Next ..... Is there a possibility to turn everything to 64bits in B4J? I have tried the below code but it crashes complaining that the rnd function bound must be positive. I guess that has to do with the fact that Java does not support unsigned type.. B4X: Copy Dim MaxLong As Long,rndlong As Int,keylong As Int, ii As Int MaxLong = Power(2,63) For ii = 0 To 63 rndlong = Rnd(0,MaxLong) key=Bit.Xor(key,rndlong) Next do you see potential workarounds? thanks!
Hi need some guidance here. I am developing a Zobrist hashing algorithm (https://en.wikipedia.org/wiki/Zobrist_hashing). for the implementation, one needs to generate a series of random numbers and then XOR them. one can use 32 bits to generate the random numbers but it would be much better to be able to use use 64 bit. a conceptual simplified idea (the actual alg needs 64 random numbers and then they are XORed is: B4X: Copy Dim MaxInt As Int,rndint As Int,key As Int, ii As Int MaxInt = Power(2,31) For ii = 0 To 63 rndint = Rnd(0,MaxInt) key=Bit.Xor(key,rndint) Next ..... Is there a possibility to turn everything to 64bits in B4J? I have tried the below code but it crashes complaining that the rnd function bound must be positive. I guess that has to do with the fact that Java does not support unsigned type.. B4X: Copy Dim MaxLong As Long,rndlong As Int,keylong As Int, ii As Int MaxLong = Power(2,63) For ii = 0 To 63 rndlong = Rnd(0,MaxLong) key=Bit.Xor(key,rndlong) Next do you see potential workarounds? thanks!
Erel B4X founder Staff member Licensed User Longtime User Jul 12, 2021 #2 There is no relation between the OS architecture and the types. A Long number is always a 64 bit number and an Int number is always 32 bit. It also has nothing to do with unsigned types. Bit.Xor works with Bytes not Longs. Rnd works with Ints. You can use ArrayXor: https://www.b4x.com/android/forum/t...xor-between-array-of-bytes.129989/post-817766 Code: Copy Dim l1(8), l2(8) As Byte Dim sr As SecureRandom 'encryption library sr.GetRandomBytes(l1) sr.GetRandomBytes(l2) Dim l3() As Byte = ArrayXor(l1, l2) You can use ByteConverter to convert the array of bytes to numbers. Upvote 0
There is no relation between the OS architecture and the types. A Long number is always a 64 bit number and an Int number is always 32 bit. It also has nothing to do with unsigned types. Bit.Xor works with Bytes not Longs. Rnd works with Ints. You can use ArrayXor: https://www.b4x.com/android/forum/t...xor-between-array-of-bytes.129989/post-817766 Code: Copy Dim l1(8), l2(8) As Byte Dim sr As SecureRandom 'encryption library sr.GetRandomBytes(l1) sr.GetRandomBytes(l2) Dim l3() As Byte = ArrayXor(l1, l2) You can use ByteConverter to convert the array of bytes to numbers.
giggetto71 Active Member Licensed User Longtime User Jul 12, 2021 #3 perfect. as usual. thanks Upvote 0