Question: Maplet for Unique Random Number Generator

This is a continuation of the new thread that was started with this post.

Code to create a maplet that generates unique random numbers from a sample space could look like:


UniqueRandom := proc( n, N )
  local R, S;
  R := rand( N );
  S := {};
  while nops(S)<n do
    S := { seq(R(),i=1..n) };
  end do;
  return( S );
end proc:

myMaplet :=Maplet(onstartup=RunWindow(MAIN),
Window[MAIN](title="Unique Random Number Generator",
[ halign=none, valign=none, inset=0, spacing=0,
    "Largest Integer in Sample Space: N = ",
    TextField['TFN']("10^20", width=8),
    "Selection Size: n = ",
    TextField['TFn']("10", width=4)
    TextBox['TBresult']("", width=75,height=8)
    Button['DoIt']("Generate", Evaluate('TBresult' = 'UniqueRandom(TFn,TFN)'), background=green),
    Button['Done']("Done", Shutdown(['TBresult']), background=pink)
Maplets[Display]( myMaplet );

You can put this code in a Maple worksheet and execute it. You can also put it in a text file, with extension .maplet. Then, double-clicking on this file will launch the maplet using the Maplet Viewer. (Note that the first maplet started can take a longer time to start due to the time required to start a Java engine.)


Please Wait...