Nestharus
o-o
- Reaction score
- 84
JASS:
library KnuthChecksum uses /*
//Knuth Variant on Division h(k) = k(k+3) mod m
//////////////////////////////////////////////////////////
//
*/BigInt //www.hiveworkshop.com/forums/jass-functions-413/system-bigint-188973/
//
//////////////////////////////////////////////////////////
function GetKnuthChecksum takes BigInt k, integer m returns integer
local BigInt c = k.copy()
local BigInt c2 = k.copy()
call c.add(3,0)
call c2.multiplyBig(c)
call c.destroy()
set c = c2.mod(m)
call c2.destroy()
return c
endfunction
endlibrary
Demo
JASS:
struct Tester extends array
private static method onInit takes nothing returns nothing
local BigInt int = BigInt.convertString("1234567890123456789", Base["0123456789"])
local integer checksum = KnuthChecksum(int, 3234567)
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, int.toString())
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, I2S(checksum))
endmethod
endstruct
Outputs:
Code:
1=1(1+3) = 4
2=2(2+3) = 10
3=3(3+3) = 18
4=4(4+3) = 28
Cycles every m