comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Simple hash or pseudo-random function
Date: Tue, 17 Jul 2018 08:09:08 +0200
Date: 2018-07-17T08:09:08+02:00	[thread overview]
Message-ID: <pik164$6bj$1@dont-email.me> (raw)
In-Reply-To: <979df026-05c7-447b-b5eb-010d85d61813@googlegroups.com>

On 07/16/2018 11:14 PM, gautier_niouzes@hotmail.com wrote:
> 
> The 64-bit value is the *input* and the output is a function of that input only.
> e.g.
> 10562032 gives always 211
> 31375393 gives always 31
> 85232830 gives always 172
> NB: the input codes can appear in a different order, so a pseudo-random *sequence* cannot be used.
> 
> I've tested different RNG's by initializing them with the input code and using only the first pseudo-random value using that seed. The good news is that they seem uniformly distributed even with successive seed values, but they are not random enough when seeds are similar. I'll check Marius' solution, or a hash function like CRC.

That makes things clearer. I would have suggested what you tried. Perhaps you 
could modify it a bit so that, for a value N, you discard the 1st N rem M values 
from the RNG before generating the output for N, and see if that improves the 
randomness of the results. M should be small enough that this is fast enough for 
your requirements but large enough to be significantly different from what 
you've already tried.

Another possibility would be to try (calling your 64-bit type U64)

subtype S8 is String (1 .. 8);

function To_S8 is new Ada.Unchecked_Conversion (Source => U64, Target => S8);

Ada.Strings.Hash (To_S8 (N) );

If Hash is a decent hash function ("It should be unlikely for similar strings to 
return the same value.") then it might be sufficiently random.

-- 
Jeff Carter
"What's the amount of the insult?"
Never Give a Sucker an Even Break
104


  reply	other threads:[~2018-07-17  6:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-16  8:20 Simple hash or pseudo-random function gautier_niouzes
2018-07-16 13:34 ` Shark8
2018-07-17  4:44   ` robin.vowels
2018-07-16 14:52 ` Marius Amado-Alves
2018-07-16 20:59   ` gautier_niouzes
2018-07-16 17:17 ` Jeffrey R. Carter
2018-07-16 21:14   ` gautier_niouzes
2018-07-17  6:09     ` Jeffrey R. Carter [this message]
2018-07-18 13:38       ` gautier_niouzes
2018-08-01  9:08         ` gautier_niouzes
2018-07-17  0:40 ` Dan'l Miller
2018-07-17  6:44 ` Paul Rubin
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox