U
U
unphasedx2019-06-06 18:01:44
PHP
unphasedx, 2019-06-06 18:01:44

How to correctly distribute (what?)?

Hello!
There are two ranges of numbers. From 1 to 10 thousand, from 1 to 10.
It is necessary to assign a number from the second range to each number from the first range so that the numbers from the second range are divided evenly, but in a different order. The number 714 of the first range can mean 8, and 715 - 3, but in general, such distributions should be more or less the same.
Ultimately, you are interested in a function that receives a number from 1 to 10 thousand by returning a number from 1 to 10.
Random is excluded.
Thank you!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Sokolov, 2019-06-06
@unphasedx

For inspiration:

  • the remainder of the division $n % 10will always return from 0 to 9. Add 1
  • hash algorithms give noticeably different results for almost similar strings: sha1() , md5()
  • any generated noise. For example, Perlin noise and on (Perlin noise). It is always predictable and depends on the input parameters. It looks random though. You need a one-dimensional version of it. Multiply by 10, floor() + 1
  • see for example Halton sequence is also a pseudo-random deterministic sequence. Write its implementation, choose some seed. The initial number from 1 to 10000 is the input coordinate. The output is 0..1, map to your range of 1..10 and round.

V
Valery, 2019-06-06
@Desay

$z = 1; 
for ($i = 1; $i <= 10000; $i++) {

    echo $i . $z;

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

T
ThunderCat, 2019-06-06
@ThunderCat

function makeMeSmall($int){
   return ceil($int/1000);
}

function makeMeSmallAgain($int){
   return substr($int,-1)?substr($int,-1):1;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question