Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
0

How to generate random vector with specific hamming weight in GF(q) ?

asked 1 year ago

Ycs gravatar image

updated 1 year ago

FrédéricC gravatar image

Dear all,

How to generate random vectors with a specific hamming weight in the finite field GF(q) ?

Thanks!

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 1 year ago

Max Alekseyev gravatar image

updated 1 year ago

If under the hamming weight you understand the number of nonzero components, then something along these lines will do the job:

def random_vector(q,n,w):
    F.<b> = GF(q, modulus='primitive')
    S = Subsets(range(n),w).random_element()
    return vector([b^randint(0,q-2) if k in S else F.zero() for k in range(n)])

Here random_vector(5^2,10,3) returns a random vector over GF(52) with 3 nonzero out of total 10 components, such as (0, 0, 2*z2 + 3, 0, 4*z2 + 1, 0, 0, 4*z2 + 1, 0, 0).

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 1 year ago

Seen: 252 times

Last updated: Mar 09 '24