Jack Feng
Jack Feng

Reputation: 971

Z3py, random different solution generation

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.

Upvotes: 0

Views: 1278

Answers (1)

alias
alias

Reputation: 30460

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.

Upvotes: 1

Related Questions