core: sort or randomize events

Before this change, the order of events was semi-random, except for
specific conditions (before, after, priority, stage).

This change either sorts the list of events, which is the default
behavior, randomizes this list, if directed to do so by the environment.

Change-Id: I3a81095dc4f90e523028b3f5b30c6045829f8ca1
Signed-off-by: Yedidyah Bar David <didi@redhat.com>
Signed-off-by: Alon Bar-Lev <alonbl@redhat.com>