# hash()

Returns a hash value for the input value.

Syntax

`hash(`source [`,` mod]`)`

Arguments

• source: The value to be hashed.
• mod: An optional module value to be applied to the hash result, so that the output value is between `0` and mod - 1

Returns

The hash value of the given scalar, modulo the given mod value (if specified).

Warning

The algorithm used to calculate the hash is xxhash. This algorithm might change in the future, and the only guarantee is that within a single query all invocations of this method use the same algorithm. Consequently, users are advised to not store the results of `hash()` in a table. If persisting hash values is required, consider using hash_sha256() instead (but note that it is far more complex to calculate than `hash()`).

Examples

``````hash("World")                   // 1846988464401551951
hash("World", 100)              // 51 (1846988464401551951 % 100)
hash(datetime("2015-01-01"))    // 1380966698541616202
``````

The following example uses the hash function to run a query on 10% of the data, It is helpful to use the hash function for sampling the data when assuming the value is uniformly distributed (In this example StartTime value)

``````StormEvents
| where hash(StartTime, 10) == 0
| summarize StormCount = count(), TypeOfStorms = dcount(EventType) by State
| top 5 by StormCount desc
``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.6179337,"math_prob":0.96924865,"size":1279,"snap":"2019-43-2019-47","text_gpt3_token_len":323,"char_repetition_ratio":0.118431374,"word_repetition_ratio":0.0,"special_character_ratio":0.2931978,"punctuation_ratio":0.084821425,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99068606,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-11-20T23:32:14Z\",\"WARC-Record-ID\":\"<urn:uuid:a5058e32-3eb9-455b-bc9c-a8f55c7db22c>\",\"Content-Length\":\"29099\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:0d8f0112-fbec-475e-b42a-e8ca9383fdae>\",\"WARC-Concurrent-To\":\"<urn:uuid:0162bad2-8a7d-4fa4-af6b-20cdff1aa389>\",\"WARC-IP-Address\":\"104.108.100.37\",\"WARC-Target-URI\":\"https://docs.microsoft.com/en-us/azure/kusto/query/hashfunction\",\"WARC-Payload-Digest\":\"sha1:UXJ5S66O6M7NARDATNRSYQX24GNJE2IK\",\"WARC-Block-Digest\":\"sha1:4D5JQ5KHKFV3YPI33KGB6LGN424OCETE\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-47/CC-MAIN-2019-47_segments_1573496670635.48_warc_CC-MAIN-20191120213017-20191121001017-00198.warc.gz\"}"}