procedure RandomExternalStabilization
input:  agents: the list of agents; environment: the environment of the agents; virtSimSteps: number of steps to run the virtual
   simulation; noChanges: the number of changes made to the system so far
output: updated noChanges
begin
 virtualEnvironment = Copy(environment)
 RunSimulation(virtualEnvironment, virtSimSteps)
 (stable, lcm) = ExternalStabilityTest(virtualEnvironment)
if not stable then
for each agent in agents do
  if Random(0, 1) < 0.1 then // with probability 0.1
    for each agent in agents such as    do
     a.SocialModels().Outcome = Random(0, 1)
     a.SocialModels().NoInteractions = 1
     noChanges = noChanges + 1
    end for
  end if
end for
end if
return  noChanges
end procedure
Pseudocode 5: Random external stabilization.