Quote Originally Posted by 2kaud View Post
Code:
if (delta_E <= 0 || ((double)rand() / (double)(RAND_MAX)) < (double)exp((double)-delta_E))
the if condition is a logical or. If either or both of the seperate conditons (left and right of the ||) is true then the if condition is true.
The first condition is easy. For the second, (double) means cast (convert) the result of what follows to be of type double. As rand() and RAND_MAX are both integers, they are first cast to double so that the result is of type double because in c/c++ an integer divided by an integer gives an integer (3/4 = 0). So the expression to the left of < gives a number of type double in the range 0 to 1 (for the probability required). The expression to the right of the < is what you stated was needed. The (double) casts are needed again to make sure that the types are as required.

See http://msdn.microsoft.com/en-us/libr...=vs.60%29.aspx
This would mean that the site (x, y) would be flipped, without doubt. If delta_E < 0, flip. If delta_E > 0, it means that the exponential is between 0 and 1, so flip. I need the flipping process to be such:

1. If delta_E < 0 flip.
2. Otherwise, flip with probability exp (-delta_E). If w = 0.7 = 70%, this means that if there are 10 sites with the same value of w, only 7 out of 10 times will site be flipped.