# Generation of random co-prime integers modulo n

2 visualizaciones (últimos 30 días)
Mohsin Shah el 6 de Mayo de 2017
Comentada: Mohsin Shah el 6 de Mayo de 2017
Suppose we have Lena image of 512x512 pixels and we want to generate random integers for every pixel of Lena image (512x512)that are co-prime to n (modulo n). How can we generate a matrix of random integers of size 512x512 co-prime to n?
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Guillaume el 6 de Mayo de 2017
Your question is missing a lot of information. What is the range for the integers to generate? What is the range for n? Should the generated numbers be all distinct or are repetitions allowed?
If the range is not too great, you could just test all the integers and only keep the ones that are coprimes:
maxvalue = 5000;
n = 127;
arraysize = [512, 512];
allnumbers = 1:maxvalue;
coprimes = allnumbers(gcd(allnumbers, n) == 1);
result = reshape(coprimes(randi(numel(coprimes), prod(arraysize))), arraysize); %if repetitions are allowed
result = reshape(coprimes(randperm(numel(coprimes), prod(arraysize))), arraysize); %if no repetition
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Mohsin Shah el 6 de Mayo de 2017
Fantastic. Thank you so much.

Iniciar sesión para comentar.

### Categorías

Más información sobre Random Number Generation en Help Center y File Exchange.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by