Ask Your Question
0

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

asked 2024-03-09 11:25:43 +0100

Ycs gravatar image

updated 2024-03-10 09:11:59 +0100

FrédéricC gravatar image

Dear all,

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

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2024-03-09 14:31:52 +0100

Max Alekseyev gravatar image

updated 2024-03-09 14:37:35 +0100

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(5^2)$ 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).

edit flag offensive delete link more

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: 2024-03-09 11:25:43 +0100

Seen: 179 times

Last updated: Mar 09