Algorithm to hash user IDs
- From: Bruce <bruce.james.lee@xxxxxxxxx>
- Date: Sun, 18 Nov 2007 13:00:00 -0800 (PST)
<Sorry this question is not tied to C#, but I could not find a good
forum that tackles such questions>
Hi
I am trying to come up with a good hashing function for user IDs in my
app. The user IDs are always of the form 0,1,2,3........
I don't know the total number of users beforehand. I am essentially
trying to write the following method:
// Given a Hash Percent, return 'true' if user ID lies between 0 and
that, 'false' otherwise.
bool IsInRange(int userId, double hashPercent);
So, if 0,1,2,3..199 are fed to this function with hashPercent as 10.5,
the function should return 'true' for 21 users.
I tried out doing some math on the numbers using mod but it did not
work. is there an easy way to do this?
Thanks
Bruce
.
- Follow-Ups:
- Re: Algorithm to hash user IDs
- From: Niels Ull
- Re: Algorithm to hash user IDs
- Prev by Date: Re: Abstract class variables question
- Next by Date: Re: Backward compatibility vs serialization
- Previous by thread: Best Approach to MS EntLib DAAB Database Object
- Next by thread: Re: Algorithm to hash user IDs
- Index(es):