From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Simple hash or pseudo-random function Date: Mon, 16 Jul 2018 19:17:48 +0200 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <5a66cd8a-e11d-4a59-bce1-8cc693b4160a@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 16 Jul 2018 17:17:48 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="c44b791de394da365df6f5b9fac2c8da"; logging-data="30964"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Ma0qF7/5QOhHSKlnohQumpHCQO9h3CzQ=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 Cancel-Lock: sha1:8czV18ZH1J/vuIFg5Xv5aeeSd6k= In-Reply-To: <5a66cd8a-e11d-4a59-bce1-8cc693b4160a@googlegroups.com> Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:53847 Date: 2018-07-16T19:17:48+02:00 List-Id: On 07/16/2018 10:20 AM, gautier_niouzes@hotmail.com wrote: > > Does someone have a function that would take an integer (range 0 .. 2**63), not uniformily distributed (it's a code with some meaning) and return a number that is pseudo-random, uniformily distributed (could be a floating-point number or an integer in a range of minimum length 365) ? > The difficulty for me is to find a very simple function. There are many that are for hashing strings, but they could be too time-consuming: it's for a number-crunching program where this function will be called billions of times, so I'm looking for something really simple (and fast :-) ). Not sure what you mean by "an integer in a range of minimum length 365". You could simply use a RNG to generate 64-bit values and xor them with your values if you want a 64-bit result. By setting the initial seed, the sequence would be repeatable. Ada.Numerics.Discrete_Random would probably serve. If it's too slow, the PragmAda Reusable Components includes KISS, a very fast, pretty good RNG. It produces 32-bit values, so you'd probably need to call it twice. -- Jeff Carter "If you don't get the President of the United States on that phone, ... you're going to have to answer to the Coca-Cola Company." Dr. Strangelove 32