How to correctly distribute (what?)?

Hello!

There are two range of numbers. From 1 to 10 thousand, from 1 to 10.

You need to each number of the first range, assigning a number of second so that the number from the second range was evenly divided, but in a different order. The number 714 of the first range may be due to the fact 8 and 715 - 3, but in General fact, such distribution should be more or less the same.

Ultimately interested in a function that receives a number from 1 to 10 thousand returning the number from 1 to 10.

Rand excluded.

Thank you!
March 23rd 20 at 19:23
4 answers
March 23rd 20 at 19:25
Solution
For inspiration:
  • the remainder of dividing $n % 10 will always return 0 to 9. Add 1
  • hash algorithms yield markedly different results for almost similar lines: sha1(), md5()
  • any generated noise. For example, the noise pearlandon (Perlin noise). He is always predictable and depends on the input parameters. It looks accidental. You need a one-dimensional version. Multiply by 10, floor() + 1
  • see, for example, the Halton sequence – also pseudosuchia determenirovana sequence. Write its implementation, choose some led. Initial number from 1 to 10000 - input coordinate. Output 0..1, napite on your range 1..10 and rounded.

Thank you! Try to go for the first option. - Ernestine commented on March 23rd 20 at 19:28
Cancellation of the first option. In this case, again, would be a strict sequence is always observed. Try the second, tell me something on the subject? - Ernestine commented on March 23rd 20 at 19:31
@Ernestine, combine 1st and 2nd - garett23 commented on March 23rd 20 at 19:34
From 1 to 10 it figuratively. Can be up to 3 and 25. As for the second range. - Ernestine commented on March 23rd 20 at 19:37
@Ernestine, but sorry, from 1 to 10 it would be possible to take,say, the average figure from the ($n + 12345) in Cuba. - garett23 commented on March 23rd 20 at 19:40
Sorry) - Ernestine commented on March 23rd 20 at 19:43
@garett23, thank you very much, Sergey, for your time and effort in resolving the issue!

Given Your interest in the issue, might be curious to see the solution from @garrett.Hintz - Ernestine commented on March 23rd 20 at 19:46
March 23rd 20 at 19:27
Solution
function getSmall($n) {
 return round(sin($n) * 4.5 + 4.5) + 1;
}

for ($n = 700; $n < 720; $n++) {
 echo getSmall($n) . "\n";
}

/*
8
4
1
3
7
10
9
5
1
2
6
9
10
6
2
1
4
8
10
7
*/
It! Thank you! - Ernestine commented on March 23rd 20 at 19:30
Simple trigonometry gives an uneven distribution. Extreme values more often than average. Compare 5 and 10. - garett23 commented on March 23rd 20 at 19:33
@garett23, Yes, you are right. About the uniform I do not like the thought, although it was indicated in the question.
@Ernestine, Then you can use recurrence using N as a seed:
function getSmall($n) {
 return ((13*$n + 7) % 10) + 1;
}

Ideally, that number in positions 13 and 7 are relatively Prime. - garrett.Hintz commented on March 23rd 20 at 19:36
March 23rd 20 at 19:29
$z = 1; 
for ($i = 1; $i <= 10000; $i++) {

 echo $i . $z;

if ($z == 10)
$z = 1;
else
++$z;

}
Doesn't fit the problem statement. Will continue the sequence. - Ernestine commented on March 23rd 20 at 19:32
March 23rd 20 at 19:31
makeMeSmall function($int){
 return ceil($int/1000);
}

makeMeSmallAgain function($int){
 return substr($int,-1)?substr($int,-1):1;
}
An example of use? - Ernestine commented on March 23rd 20 at 19:34
@Ernestine, XS, can you explain what this tepee with the Indians, then I can better tell what is and what to use. - kyleigh.McKenzi commented on March 23rd 20 at 19:37
You tell me, I'll explain. I think the problem you described, and while the tepee with the Indians this is the only answer.

There are 100 of thousands of materials, say, and it's a set of some number of headers, may 13. Need on the fly such titles evenly to assign to the materials, starting only from the first IDs.

Thank you. - Ernestine commented on March 23rd 20 at 19:40
@Ernestine, hmm, the easiest solution is just take the last digit in the original value will be unique the distribution of absolute uniformity. You can also play around with mathematical functions and a square root / cube rounded and take the last digit, or a number divided by PI with some accuracy. The terms of distribution are still poorly understood, in addition still do not understand why not the same with Rand? For reasons of common educational values? - kyleigh.McKenzi commented on March 23rd 20 at 19:43
The last digit is excluded as in this case, it will be observed the sequence, the material 1 is the first header, the second the second, ..., and so the same headers can be more than 9.

Rand excluded, there are reasons.

But thank you! - Ernestine commented on March 23rd 20 at 19:46
@Ernestine, strict consistency is impossible, and not Rand?
you contradict yourself. - Delpha_Kuph commented on March 23rd 20 at 19:49

Find more questions by tags AlgorithmsPHP