Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个生成分数的公式,例如 score = UnixTimeOfNow(),但我想得到 (1,n) 范围内的最终分数,例如 (1,100)。那么如何将分数映射到特定范围?
要映射score到(1, n)包含范围内的值,您可以这样做
score
(1, n)
score = 1 + (score % n);
(那是 Java,C/C++ 语法。)
%是表示例如205 % 100is的模运算符5。
%
205 % 100
5