0
from z3 import *
import random
a = Int('a')
b = Int('b')

s = Tactic('qflra').solver()
s.add(a > 10)
set_option('smt.arith.random_initial_value', True)
set_option('smt.random_seed', random.randint(0, 2 ** 8))

while s.check() == sat:
    m = s.model()
    print m[a]
    s.add(a != m[a])
    set_option('smt.random_seed', random.randint(0, 2 ** 8))

The result seems to be only randomed for a second... Then it just started to give consecutive numbers.

4294966399
4294966398
4294966397
4294966396
4294966395
4294966394
4294966393
11
12
13
14
4294966400
15
16
17
18
19

How can I make it more random? At least, not a list of consecutive numbers. My optimal goal is to have a list of solutions that are rather uniformly distributed in the solution space.

Jack Feng
  • 895
  • 2
  • 9
  • 24
  • [This post](https://stackoverflow.com/questions/24330928/z3py-randomized-results-phase-selection-not-random) might be helpful. In general, the random seed is used to make sure the result becomes predictable, not to get uniformly distributed solutions. – JohanC Feb 03 '20 at 13:31

1 Answers1

1

I think you're conflating what randomization does with sampling. As @JohanC pointed out, you usually fix a random seed to get consistent results in SMT across multiple runs. Just because you change the seed, does not mean you'll get a different result. Sampling is an entirely different (and much more difficult) problem than setting some random numbers. Otherwise, what you're doing is correct; To find all the settable options, run z3 -p > options.txt and look inside options.txt for the keywords seed and random.

alias
  • 28,120
  • 2
  • 23
  • 40