script to calculate Random field