My app generates thousands of files, and I'd like to evenly distribute them into some dirs.
How the files are divided should be predictable, as I have a client which requests them to the server. I.e. if I have file "100002.xml", I need to know under which dir it is located.
The files have names like ids in a database, like 1.xml, 2.xml, 1000000.xml and so on. There can be big holes between numbers, so I can have files 1-1000 and then 100000-199999
Last time I had many files beginning with 1, so creating dirs like 0-9 doesn't work, because almost all file would go into the "1" dir.
I cannot think to a method to evenly distribute the files, how could I do?
I can also accept to have dirs with no more than n files.
I'm able to make a script to split the files into multiple dirs but not in a way that is predictable. I'd like to create as fewer dirs as possible.
Edit: my client cannot search nor I cannot have a script on the server to handle the requests: I have a javascript method which get a file from an Apache server and I cannot have any script to handle the requests
Edit 2: I think that my question really is: what hash function can I use to map integers to a uniform distribution of integers even if the source integers are not uniformly distributed?