I want to create an array that sends a pixel in a specific direction.
It has four options: Forward, Backward, Left, Right
Each direction has an associated score that is its probability of sending the pixel in a specific direction.
Example:
Direction[Forward] = 20;
Direction[Backward] = 12;
Direction[Left] = -5;
Direction[Right] = 2;
How can I make the number for each key in the direction array equal the probability of moving the pixel? I want the negative number to play into the probability albeit a small chance.
Currently I copy each direction key into a new array the number of times as it's probability score, then generate a random number against the new array, but that doesn't work on negative numbers, so I change them to +1 in advance. Obviously this doesn't scale on negative numbers.
How can I create a probability for each array key regardless if it's a positive or negative number?