Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Plain Text by ADDS ( 17 years ago )
Generate two random numbers between 0 and 1 using the rand(1,2) function. 
If the first of the random numbers is less than 1/4 reduce x by 1, if it is between 1/4 and 3/4 leave x unchanged and if it greater than 3/4 increase x by 1. In this way the probability of moving left is 1/4 , the probability of remaining at the same x coordinate is 1/2 and the probability of moving right is 1/4. 

Repeat the process with the second random number and the y coordinate. In this way the particle can move to any of the locations indicated below. It will stay put with probability 1/4 X 1/4 = 1/4 will move due north, south, east or west with probability 1/2 X 1/4 = 1/8 each and will move diagonally with probability 1/4 X 1/4 = 1/16. Note that 1/4 + 4 X 1/8 + 4 X 1/16 = 1.

 

Revise this Paste

Parent: 12572
Your Name: Code Language: