# Algorithm to convert md5 (or maybe another hashing method?) to integer where it is possible to set possible resulting integer ranges (eg: 1-10000)?

Active3 hr before
Viewed126 times

algorithmconvert
90%

2 If you're hashing into a 10K range, then cryptographic hashing is overkill. The practical guarantee it gives (no collisions) is completely destroyed by the small range. You'd be better off using a faster hash that maintains a reasonable spread. crc32 is one that has several command line and library implementations. – phs Sep 5 '11 at 8:27 , Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers ,Note however that many different hashes will convert to the same integer; this is unavoidable with any sort of conversion to your integer range, as the modulo operation essentially maps a larger set of numbers (in this case, 128 bits, that is numbers from 0 to 340,282,366,920,938,463,463,374,607,431,768,211,456) to a smaller set of numbers (less than 17 bits, numbers from 1 to 100,000).,the code below seams to accomplish what we want. please chime in if this can be (not the code, its just for reference, but if the idea) improved at all. running the code below will result in 6305 / 10000 unique results. that in our case is good enough.

the code below seams to accomplish what we want. please chime in if this can be (not the code, its just for reference, but if the idea) improved at all. running the code below will result in 6305 / 10000 unique results. that in our case is good enough.

```< ?

\$final = array();

\$range = 10000;

for (\$i = 1; \$i <= \$range; \$i++) {

\$string = 'this is my test string - attempt #'.\$i;

echo 'initial string: '.\$string.PHP_EOL;

\$crc32 = crc32(\$string);

echo 'crc32 of string: '.\$crc32.PHP_EOL;

\$postalgo = \$crc32 % \$range;

echo 'post algo: '.\$postalgo.PHP_EOL;

if (!in_array(\$postalgo, \$final)) {
\$final[] = \$postalgo;
}

}

echo 'unique results for '.(\$i - 1).
' attempts: '.count(\$final).PHP_EOL;

?
>```
88%

Rails “Where” method - greater than (“>”) using endless ranges I just recently discovered a neat trick to replace greater than / less than in rails #code# in which you can use a range to replace the string version of where:... vpaucek · saved on 2 months ago ,I just recently discovered a neat trick to replace greater than / less than in rails #code# in which you can use a range to replace the string version of where:...,Since MD5 (and SHA-1, etc.) will give you 128 bits of data (in PHP, you'll get it in hexadecimal string notation, so you need to convert it to an integer first). That number modulo 10000 will give you your integer.,I was creating a code to encode an input word.Letters in the input text is converted to a number and stored in a list.Here is the code is used, and so on..... B...

the flow would ideally look like this:

`string - > md5(string) - > algo(md5(string), range) - > resulting integer within range`
72%

Example: design a hash table for a map storing entries as (SSN, Name), where SSN is a 9-digit positive integer.,The hash code is applied first, and the compression function is applied next on the result, i.e., h(x) = h2(h1(x)). , An alternative hash code is to sum an integer representation of the high-order bits with an integer representation of the low-order bits.,Change the structure of the hash table so that each array location can represent more than one value

65%

The data type of the result is BINARY with the result length determined by the function name as shown in Table 1.,The hashing functions return a 128-bit, 160-bit, 256-bit, or 512-bit hash of the input data, depending on the algorithm selected.,Security flaws have been identified in both the SHA1 and MD5 algorithms. You can find acceptable hash algorithms in applicable compliance documentation, such as National Institute of Standards and Technology (NIST) Special Publication 800-131A.

`VALUES HEX(HASH_MD5('ABCDEFGHIJKLMNOPQRSTUVWXYZ'))`
`5156 BECBC019E3F0F9520B143435427E`
75%

Our goal is to create a hash function that minimizes the number of collisions, is easy to compute, and evenly distributes the items in the hash table. There are a number of common ways to extend the simple remainder method. We will consider a few of them here.,We can also create hash functions for character-based items such as strings. The word “cat” can be thought of as a sequence of ordinal values.,len() Return the number of key-value pairs stored in the map.,Figure 12: Collision Resolution with Chaining¶

```>>> ord('c')
99
>>>
ord('a')
97
>>>
ord('t')
116```