Move random test util code from setup_common to random
Summary:
as many of the unit tests don't use this code
This is a backport of core#26940 (partial) and core#27425
https://github.com/bitcoin/bitcoin/pull/26940/commits/81f5ade2a324167c03c5ce765a26bd42ed652723
This is a depency of core#25325
Test Plan: ninja check
Reviewers: #bitcoin_abc, Fabien
Reviewed By: #bitcoin_abc, Fabien
Differential Revision: https://reviews.bitcoinabc.org/D16155