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!

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!

asked March 23rd 20 at 19:23

4 answers

answered on

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 pearl
*and*on (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.

answered on

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! commented on March 23rd 20 at 19:30

Simple trigonometry gives an uneven distribution. Extreme values more often than average. Compare 5 and 10. 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:

Ideally, that number in positions 13 and 7 are relatively Prime. commented on March 23rd 20 at 19:36

@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. commented on March 23rd 20 at 19:36

answered on 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. commented on March 23rd 20 at 19:32

answered on 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? 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. 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. commented on March 23rd 20 at 19:40

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. 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? 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! commented on March 23rd 20 at 19:46

Rand excluded, there are reasons.

But thank you! commented on March 23rd 20 at 19:46

@Ernestine, strict consistency is impossible, and not Rand?

you contradict yourself. commented on March 23rd 20 at 19:49

you contradict yourself. commented on March 23rd 20 at 19:49

Find more questions by tags AlgorithmsPHP

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