summaryrefslogtreecommitdiff
path: root/xmake/core/base/hash.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2025-10-02 00:42:11 +0800
committerruki <[email protected]>2025-10-02 00:42:11 +0800
commit0938e19d1ff2711224c6e8675366fed845b28c0d (patch)
treeb140bc1308ff9f0a65787a1aad7a5d7610f3cc5f /xmake/core/base/hash.lua
parent0046d446d0f3f31cb1a89081ca5841b79918f904 (diff)
support old core
Diffstat (limited to 'xmake/core/base/hash.lua')
-rw-r--r--xmake/core/base/hash.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/xmake/core/base/hash.lua b/xmake/core/base/hash.lua
index b4b42371d..f08c562aa 100644
--- a/xmake/core/base/hash.lua
+++ b/xmake/core/base/hash.lua
@@ -31,6 +31,9 @@ local libc = require("base/libc")
hash._md5 = hash._md5 or hash.md5
hash._sha = hash._sha or hash.sha
hash._xxhash = hash._xxhash or hash.xxhash
+hash._rand32 = hash._rand32 or hash.rand32
+hash._rand64 = hash._rand64 or hash.rand64
+hash._rand128 = hash._rand128 or hash.rand128
-- generate md5 from the given file or data
function hash.md5(file_or_data)
@@ -136,5 +139,32 @@ function hash.strhash128(str)
return hash._xxhash(128, data, size)
end
+-- generate random32 hash
+function hash.rand32()
+ if hash._rand32 then
+ return hash._rand32()
+ else
+ return hash.strhash32(tostring(math.random()))
+ end
+end
+
+-- generate random64 hash
+function hash.rand64()
+ if hash._rand64 then
+ return hash._rand64()
+ else
+ return hash.strhash64(tostring(math.random()))
+ end
+end
+
+-- generate random128 hash
+function hash.rand128()
+ if hash._rand128 then
+ return hash._rand128()
+ else
+ return hash.strhash128(tostring(math.random()))
+ end
+end
+
-- return module: hash
return hash