Items tagged with random random Tagged Items Feed

Coding in key generation of RSA Cryptosystem

message :=123456;

u := nextprime(RandomTools[Generate](integer(range = 10^100 .. 10^(110-1))));

v := nextprime(RandomTools[Generate](integer(range = 10^100 .. 10^(110-1))));

N := u*v;

phi := (u-1)*(v-1);

In RSA cryptosystem, the encryption or decryption of message only can be existed between range 1<=message<=N. This means that if the value of message bigger than N value then we can't get back the original value when performing decryption.Thus, wanna to ask that how can we create a coding so that the system will recognise the random integer u and v whether lie between range 1<=message<=N, means wanna crete a coding that if  N>=message then it will continue to the phi step whereas if message>=then the system need to regenerate the u and v until it satisfy the condition  1<=message<=N .Thus please help as i am a beginner in Maple.Thanks.

May I know any command can help to random selected a position in a group of bit number then flip that number but with condition after convert to bytes the number cannot be more than 7?

For example,

I have integer 3, i convert to binary become 0000011

then i need a command to random select a position to flip and only one bit can be flipped.

After that the group of flipped number will convert back to decimal, but total value cannot more than 7? any command can solve?  Thank you. 

How to generate a random normal distribution of points around the point [3,15] for example?

Wanna ask that how to make maple program to select a random binary number in base 2.

For example, suppose that we have a value 11101100(8 bit which in base 2),then how to let Maple to select a binary number randomly and the binary bit of the random number always shorter than the previous then sum it together?

For example the program will select 1101101(7-bit) and sum it together(11101100+1101101=101011001,in base 2)

Can somebody help me thanks.

I have use a ''for cycle'' in order to get a series of points. I would like to save those points in a vector in order to use it for the ''PolynomialFit'' comand. The problem is that the points that I save are sort randomly. How can I take the value of the vector A in the right sequence? in the underline string you can plot the walue of A over t (which is not sorted). I can not use the sort command as I used for t even for A because the points are not increasing.

This is my code:


Atot := 0:

for ii from 0 by 0.01 to 2 do

PtotFkt := ii->  ii^2 :

Ptot := PtotFkt(ii):

Atot := Atot+0.01*Ptot:

A[ii] := Atot: #Save points in a Table

t[ii] := ii: #Save point in a table

end do;

AV := convert(A, list): #conversion from table to list
nops(AV);  #number of points

timme := convert(t, list): #conversion from table to list
nops(timme); #number of points


with(Statistics); #PolynomialFit

X := Vector(AV, datatype = float);

Y := Vector(sort(timme), datatype = float);

plot(Y, X, style = point, symbol = asterisk, color = blue);

regress := PolynomialFit(10, X, Y, time);

curve1 := plot(regress, time = 0 .. 2);

Hei, I'm trying to create a random walk in the plane, with constant step length (=1) and the angle between two consecutive steps are decided by a probability density function. I just can't seem to find out how I should implement the density function into my worksheet.

The probability density function is: p(phi)=(1/4)*cos(phi/2), on the interval [-Pi,Pi].
And  I think i managed to do it by selecting a random angle, but don't know how to generate a random angle given this probability function. Any ideas? It'd be highly appreciated!

How to produce such a plot with Maple?
enter image description here

The difficulty is that the geom3d package does not include a command for a cylinder whereas
the plottools package has the cylinder command, but does not have a tool to determine whether
two random cylinders intersect.

Working on a code to create random lines. Here is the code: 

M:=1; N:=1500; R3:=rand(1..3): # M=lines, N=steps

for i from 1 to M do
   for j from 0 to N do
   if j=1 then X[i,1]:=1; Y[i,1]:=0;
    elif j>1 then
        if r=1 then X[i,j]:=2*X[i,j-1]-X[i,j-2]; Y[i,j]:=2*Y[i,j-1]-Y[i,j-2]
        elif r=2 then X[i,j]:=X[i,j-1]+Y[i,j-1]-Y[i,j-2]; Y[i,j]:=Y[i,j-1]-X[i,j-1]+X[i,j-2];
        elif r=3 then X[i,j]:=X[i,j-1]-Y[i,j-1]+Y[i,j-2]; Y[i,j]:=Y[i,j-1]+X[i,j-1]-X[i,j-2];
      end if;
    end if;
  end do:
end do:

Now the code works fine. But I don't want the lines to cross its own path. I want it to stop if R[i,j]=R[i,k] for any 0<k<i-2 for j=0..N. What I have so far is:

for i from 1 to M do
  for j from 1 to 40 do
    for k from 1 to j-2 do
     if R[i,j]=K[i,k] then x:=j; print(b[i]=j); break; end if;
     end do;
   end do;
end do;

Now it works aswell, but it doesn't stop when it hits the crossing point. I want it to stop so i get one b[i]=j per M. So I need it to break two for loops so that it goes through i M times and stops everytime it reaches a crossing point


I'm trying to create a code that allows me to model a random walk for 50 people. I'm using r[i]= {X[i],Y[i]} where i is the number of steps and r[i] the position in the i-th term.

I have created three possibilities:
2r[i]-r[i-1] - go stright forward

{x[i]+y[i]-y[i-1],y[i]-x[i]+x[i-1]} - turn right

{x[i]-y[i]+y[i-1],y[i]+x[i]-x[i-1]} - turn left

The first step I want them to make is to point (1,0) and from there I want them to take 1500 random steps.

M:=50; N:=1500; R3:=rand(1..3):

for i from 1 to M do
for j from 1 to N do
if j=1 then X[i,1]:=1; Y[i,1]:=0;
elif j>1 then
if r=1 then R[i,j]:=2*R[i,j]-[R[i,j-1];
elif r=2 then R[i,j]:=[X[i,j-1]+Y[i,j-1]-Y[i,j-2],Y[i,j-1]-X[i,j-1]+X[i,j-2]];
elif r=3 then R[i,j]:=[X[i,j-1]-Y[i,j-1]+Y[i,j-2],Y[i,j-1]+X[i,j-1]-X[i,j-2]];
end if;
end if;
end do:
end do:


The first and second step works, but from there it seems Maple is having trouble getting the correct digigts, because the formulas coming out are correct.

I have tried putting in different types of X, Y and R reads, but have gotten stuck. If someone could help me spot what this code is missing I would be very gratefull. I think Maple is just missing a way of reading X and Y but i might be wrong.

How can I generate some n-tuple random list of integers s.t. any component is between -30 and 50? For example if n=5 then four random of such 5-tuple are

[-1,2,8,7,9] , [0,-9,2,-3,-5] , [4,5,3,-8,-1] , [12, -5, 0, 6,8]

Perhaps the question is trivial, but I could not find the solution.

I am solving numerically an ODE (e.g., a simple harmonic oscillator) with the righthand side that contains a random part. For example it is

eq:=diff(a(t),t,t) + a(t) = (1+0.01*R(t))*cos(5*t);

where R(t) is a random function of t. How can I make such a function?

The naive attempt: 

eq:=diff(a(t),t,t) + a(t) = 3.*(1+0.1*rand()/1000000000000.)*cos(5.*t);

gave me a fixed (while random) value, e.g.


But, I need this coefficeint to be random each time step.

Any suggestions are very welcome!






I have a problem with creating a function contains n-dimensional independent variables with random function .. The function looks like:

f(x)=sum(U[i] * abs(x[i])^i,i=1..n)

where U is a random between 0 and 1


For 1-dimensional problem, it will be like:


The plot by MATLAB will be:


While, for 2-dimensional problem, it will be like:

f(x[1],x[2])=U[1]*abs(x[1]) - (-U[2]*abs(x[2])^2)


and the plot with MATLAB will be:


The MATLAB code is:

R=1000; % steps resolution

for j=1:length(x1)

    % For 1-dimensional plotting

    % For 2-dimensional plotting
    for i=1:length(x2)







I have used Maple because of its great graphics and animation, and for the mathematical analysis capability. However, to animate the above problem for 1- and 2-dimensional problems, I always fail!

My attempt has been just successed to plot 1-dimensional problem (without animation) .. And it tooks long-time with many codes!


X := Statistics:-RandomVariable(('Uniform')(0, 1));
R := Statistics:-Sample(X, 1000);

Vect := abs(Vector[column]([seq(0 .. 10, 10/999)]));

V := `~`[`-`](Vect, 5);

Mat := Multiply(V, R);

f := ArrayTools:-Diagonal(Mat);

F := abs(f);

Axis := Transpose(V);

f5 := plot(Axis, F, style = line);


And finally I got the graph:


But the problem is:

How can I animate it? Maybe I need to express it with new Maple code?

How can I plot and animate it when n=2?



I am trying to find the pdf of the inverse of a random variable X, that represents a distribution I defined. I currently have : 

T:=Distribution(PDF=(x->piecewise(0<x and x<1,1/4,3<x and x<5,3/8,0)));

but this seems to be incorrect as I get a message saying T1:=RandomVariable(Y) is being passed a wrong argument. 

What is the right way to obtain the pdf of 1/X?


In Maple TA in blackboard I am creating an assignment. Each week a part of the assignment will be posted. I was wondering if it is possible to have the same random variables in differnet assignmemts. That way the students can use their prior work. 

So in week one the students will get a set of random variables. But in week two a new assignment is posted were I want the same variables to come up for each student. Is this possible? (all students will have their own unique set of variables)

Hi all,


I want to create a (set of) samples from an own distribution. The distribution itself is a normal distribution, but with some 'gaps', as shown below:

plot(exp(-(t-10)^2/(2*(0.5e-1*10)^2))*piecewise(t<9,0,t<9.9,1, t<10.1,0, t<11,1), t = 8.5 .. 11.5)

(It is supposed to represent the distribution of discrete resistor values (e.g. 10 ohms), where not only the values above the tolerance (e.g. 10%) are removed, but also those who can be sold as higher precision resistors (eg. 1%). The mean, lower tolerance and higher tolerance should be variables).

Because of the fact that in order to be able to use the Sample function, the PDF should be twice differentiable, the 'truncation' in the middle is realised using logistic functions.

I am able to create said distribution, and produce a DensityPlot, but when I try to take a (even a single) Sample from a RandomVariable from that distribution, Maple keeps calculating and no sample is produced.

GetDist := (mu, alpha, beta) -> Distribution(PDF = unapply(LotRPDF(t, mu, alpha, beta), t)):
T := GetDist(10, .1, 0.1e-1);
RandomR := RandomVariable(T):
Sample(RandomR, 1);

Where LotRPDF is the function depicted above, mu is the mean (10), alpha is the maximum tolerance (10%), , beta is the minimum tolerance (1%)

Am i overlooking something simple? Or is there a more fundamental error in my approach? I've added the maple sheet with more details.


1 2 3 4 5 6 Page 1 of 6