-1

I have the need to consistently generate a number between 1-5 from a byteArray input.

I was thinking to use a CRC32 checksum so I have a long number.

I would need to translate the long to something between 1-5.

Is it a good solution? How could I achieve this transformation in a consistent way in Java?

Thanks

Update: to better understand my requirements: I have a set of images on my website and I want these to be served by multiple subdomains to parallelize browser downloads. I'm going to have 5 subdomains serving the same images. I want one image to be requested only to one subdomain to use browser caching consistently. more here Reduce site load time with multiple CDN sub-domains

spike07
  • 809
  • 2
  • 12
  • 21

1 Answers1

0

If you want a number that depends on the contents of the array, you can use:

int yourNumber = Arrays.hashCode(yourArray) % 5 + 1;
Vlad
  • 18,195
  • 4
  • 41
  • 71