I have 2 int, lets call them x and maxoffset, and a List of ints called y. I have a list of y (lets say its 2 long). 1 of the values is 0 and the other is -4. On x I have a int that I can change, and I want it to choose the closest number if the distance is less than or equal to maxoffset. This means if maxoffset is 2 and my number that I wrote for x is -2 then both 0 and -4 have a equal chance of being chosen since they are equal distance. if I choose -1 then the value 0 has a chance of being chosen, but -4 has no chance because -1 is 3 away from -4, which is more than the maxoffset. If that -4 was a -3 then since 0 is closer to -1 than -3 is, its more likely that 0 gets chosen, but the -3 can still get chosen since its within the max offset. Keep in mind this is just an example and I will end up having the list be much longer.

EDIT: Figured out a way to make the offset work as intended, I just now need to find out a way for weighting so the one closer to the variable is more likely to be chosen instead of equal chance