Processing math: 16%

First time here? Check out the FAQ!

Ask Your Question
0

Generate a random integer with some condition

asked 0 years ago

hamouda gravatar image

I want to generate a random integer of bitsize n with some condition. For example, if we want to generate an integer e of 71 bits satisfying 3e=1mod, in which the generation is fast to some extent. How to do this in sage.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 0 years ago

Max Alekseyev gravatar image

3e\equiv 1\pmod5 means that e=5k+2 for some k. Then e having n=71 bits means e\in[2^{n-1},2^n-1], which translates into k\in \big[\lceil (2^{n-1}-2)/5\rceil, \lfloor (2^n-3)/5\rfloor\big]. Hence, it's enough to generate such a random integer k, and then compute e out of it:

n = 71
L = ceil((2^(n-1)-2)/5)
U = (2^n-3)//5
import random
e = random.randint(L,U)*5 + 2
Preview: (hide)
link

Comments

@Max Alekseyev, It is a good idea for this example. If it is possible, is there a general way to generate an integer of bitsize n, with a specific condition. ??

hamouda gravatar imagehamouda ( 0 years ago )

What specific condition?

Max Alekseyev gravatar imageMax Alekseyev ( 0 years ago )

A general condition according to my choice

hamouda gravatar imagehamouda ( 0 years ago )
1

It depends on the type of condition. Any modular condition can be treated similarly to what's done in my answer.

Max Alekseyev gravatar imageMax Alekseyev ( 0 years ago )

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: 0 years ago

Seen: 249 times

Last updated: Jun 20 '24