Random numbers within a speicified finite field

671 views
Skip to first unread message

mahm....@gmail.com

unread,
Mar 16, 2017, 7:00:55 AM3/16/17
to sage-support
I am trying to generate a matrix that contains randomly generated finite fields' elements.
Tried several approaches, basically working on this function 
I'll highlight to you what the problem actually is, ignoring the matrix part

sage : randint (1, 255)
for a finite field
sage : k.<a> = GF(2^8)
I coerce it as follow 
sage : randNum = k (randint(1,255))
but I find it produces to me elements in GF(2)
only 0,1 

How can I pull random numbers from any desired field ?

Dima Pasechnik

unread,
Mar 16, 2017, 7:09:36 AM3/16/17
to sage-support
one should not think about elements of finite fields as "numbers"
Here is a way:

sage: F=GF(8)

sage: F.random_element()

0

sage: F.random_element()

z3^2



Anyhow, Sage has a dedicated function for your task:

sage: matrix.random(GF(8),4,2)


[z3^2 + z3 + 1             0]

[            0        z3 + 1]

[            0             0]

[       z3 + 1     z3^2 + z3]

mahm....@gmail.com

unread,
Mar 16, 2017, 8:06:12 AM3/16/17
to sage-support
Thank you very much I wouldn't require any better answer than that. The literal manifestation of the word "On point" XD
Despite the fact I would need this int to field coercion in some point because I will be taking number as arguments in Command line.
I'll ask it later in a separate post if I can't work it out, that is once I get into it.
Reply all
Reply to author
Forward
0 new messages