B
B
Barrakuda742019-03-11 13:43:21
Algorithms
Barrakuda74, 2019-03-11 13:43:21

Algorithm in php or js - how to get a numeric value from the XY interval from any hash?

Those. we have a certain set of data for the object.
Let's say z = [6, 1.5, 23, 34, 'green'];
I need the function to give a value from 5 to 15 based on these parameters.
Let's say we do some md5(z[0] + z[1] + z[2] + z[3] + z[4]), we get a hash.
But how to optimally squeeze a value from 5 to 15 out of it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2019-03-11
@Barrakuda74

yes, at least split the hash into bytes, add, take the remainder of the division by 10 and add 5.

I
Ihor Bratukh, 2019-03-11
@BRAGA96

For example like this:

class Hash {
    static encode(content) {
        return btoa(unescape(encodeURIComponent(content)));
    }

    static decode(content) {
        return decodeURIComponent(escape(atob(content)));
    }
}

const encode = Hash.encode(JSON.stringify([6, 1.5, 23, 34, 'зелёный']));

console.log(encode);

const decode = Hash.decode(encode);

console.log(JSON.parse(decode));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question