const int RANGE = 100;
int seed = 0;
int value = 0;
while(true)
{
if(seed >= RANGE * 2)
seed = 0;
if(seed <= RANGE)
value = seed;
else
value = RANGE * 2 - seed;
++seed;
}
value將按0→100→0→100循環變化
補充: Unity中的Mathf.PingPong()函數可以實現此功能