diff mbox series

[OSSTEST,6/7] mfi-common: Provide stripy_rand

Message ID 20210122155603.23402-6-iwj@xenproject.org (mailing list archive)
State New, archived
Headers show
Series [OSSTEST,1/7] target_editfile_kvp_replace: Support changing multiple keys | expand

Commit Message

Ian Jackson Jan. 22, 2021, 3:56 p.m. UTC
We will use this in a moment.

Signed-off-by: Ian Jackson <iwj@xenproject.org>
---
 mfi-common | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/mfi-common b/mfi-common
index 34b0c116..35efd233 100644
--- a/mfi-common
+++ b/mfi-common
@@ -31,6 +31,18 @@  stripy () {
   eval "$out_vn=\"\$out_$out_val\""
 }
 
+stripy_rand () {
+  # feel free to pass not-real values for $job
+  # if desired to perturb the hash, etc.
+  local job="$1"; shift
+  local out_vn="$1"; shift
+  local hash="$( echo "$job $out_vn" | sha256sum )"
+  hash="${hash:0:7}"
+  local ix=$(( (0x$hash * $#) / 0x10000000 + 1 ))
+  out_val="${@:$ix:1}"
+  eval "$out_vn=\"\$out_val\""
+}
+
 branch_wants_migrupgrade_tests () {
   case "$branch" in
     xen-3.*-testing) return 1 ;;