How to generate random points without duplication?How to generate a random matrix with specific parameters?How do I keep a random value associated with a locator point as points are added?Generate nonoverlapping random circlesGenerating uniform random points over a binary imageHow to generate a random pulsar graph between two points?How to generate random natural numbers in $[1, infty)$?How to generate random numbers for Beta distribution in a range?3D random walk between two end pointsGenerate a random Fibonacci sequenceGenerating random coordinates (3D) with constraint

Is it legal in the UK for politicians to lie to the public for political gain?

How bad would a partial hash leak be, realistically?

Adding two lambda-functions in C++

What is the advantage of carrying a tripod and ND-filters when you could use image stacking instead?

Building a road to escape Earth's gravity by making a pyramid on Antartica

Can a magnetic field of an object be stronger than its gravity?

Word for a small burst of laughter that can't be held back

How is it possible that Gollum speaks Westron?

How would you say “AKA/as in”?

Why is the relationship between frequency and pitch exponential?

Why did a party with more votes get fewer seats in the 2019 European Parliament election in Denmark?

How could a government be implemented in a virtual reality?

Why don't B747s start takeoffs with full throttle?

Company did not petition for visa in a timely manner. Is asking me to work from overseas, but wants me to take a paycut

When writing an error prompt, should we end the sentence with a exclamation mark or a dot?

Pronoun introduced before its antecedent

You've spoiled/damaged the card

Is there any word or phrase for negative bearing?

Did Darth Vader wear the same suit for 20+ years?

Should I "tell" my exposition or give it through dialogue?

Do adult Russians normally hand-write Cyrillic as cursive or as block letters?

If Boris Johnson were prosecuted and convicted of lying about Brexit, can that be used to cancel Brexit?

X-shaped crossword

Is the decompression of compressed and encrypted data without decryption also theoretically impossible?



How to generate random points without duplication?


How to generate a random matrix with specific parameters?How do I keep a random value associated with a locator point as points are added?Generate nonoverlapping random circlesGenerating uniform random points over a binary imageHow to generate a random pulsar graph between two points?How to generate random natural numbers in $[1, infty)$?How to generate random numbers for Beta distribution in a range?3D random walk between two end pointsGenerate a random Fibonacci sequenceGenerating random coordinates (3D) with constraint













2












$begingroup$


In generating a list of random 2D integral coordinates e.g. u1,v1, u2,v2, u3,v3,..., how can one write a condition specifying that no point is repeated, i.e no ui,vi == uj,vj?










share|improve this question









New contributor



spaced is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$











  • $begingroup$
    ui, vi are real numbers?
    $endgroup$
    – kglr
    8 hours ago










  • $begingroup$
    Integers from 0 to 20, so it happens frequently.
    $endgroup$
    – spaced
    8 hours ago










  • $begingroup$
    To add more detail to the question - the points are being generated by an optimization routine (NMaximize); I think the only way I can control for duplicates is by specifying a constraint on the ui, vi being generated.
    $endgroup$
    – spaced
    7 hours ago















2












$begingroup$


In generating a list of random 2D integral coordinates e.g. u1,v1, u2,v2, u3,v3,..., how can one write a condition specifying that no point is repeated, i.e no ui,vi == uj,vj?










share|improve this question









New contributor



spaced is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$











  • $begingroup$
    ui, vi are real numbers?
    $endgroup$
    – kglr
    8 hours ago










  • $begingroup$
    Integers from 0 to 20, so it happens frequently.
    $endgroup$
    – spaced
    8 hours ago










  • $begingroup$
    To add more detail to the question - the points are being generated by an optimization routine (NMaximize); I think the only way I can control for duplicates is by specifying a constraint on the ui, vi being generated.
    $endgroup$
    – spaced
    7 hours ago













2












2








2


1



$begingroup$


In generating a list of random 2D integral coordinates e.g. u1,v1, u2,v2, u3,v3,..., how can one write a condition specifying that no point is repeated, i.e no ui,vi == uj,vj?










share|improve this question









New contributor



spaced is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$




In generating a list of random 2D integral coordinates e.g. u1,v1, u2,v2, u3,v3,..., how can one write a condition specifying that no point is repeated, i.e no ui,vi == uj,vj?







random






share|improve this question









New contributor



spaced is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share|improve this question









New contributor



spaced is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share|improve this question




share|improve this question








edited 7 hours ago









user64494

3,90111323




3,90111323






New contributor



spaced is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








asked 8 hours ago









spacedspaced

283




283




New contributor



spaced is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




New contributor




spaced is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • $begingroup$
    ui, vi are real numbers?
    $endgroup$
    – kglr
    8 hours ago










  • $begingroup$
    Integers from 0 to 20, so it happens frequently.
    $endgroup$
    – spaced
    8 hours ago










  • $begingroup$
    To add more detail to the question - the points are being generated by an optimization routine (NMaximize); I think the only way I can control for duplicates is by specifying a constraint on the ui, vi being generated.
    $endgroup$
    – spaced
    7 hours ago
















  • $begingroup$
    ui, vi are real numbers?
    $endgroup$
    – kglr
    8 hours ago










  • $begingroup$
    Integers from 0 to 20, so it happens frequently.
    $endgroup$
    – spaced
    8 hours ago










  • $begingroup$
    To add more detail to the question - the points are being generated by an optimization routine (NMaximize); I think the only way I can control for duplicates is by specifying a constraint on the ui, vi being generated.
    $endgroup$
    – spaced
    7 hours ago















$begingroup$
ui, vi are real numbers?
$endgroup$
– kglr
8 hours ago




$begingroup$
ui, vi are real numbers?
$endgroup$
– kglr
8 hours ago












$begingroup$
Integers from 0 to 20, so it happens frequently.
$endgroup$
– spaced
8 hours ago




$begingroup$
Integers from 0 to 20, so it happens frequently.
$endgroup$
– spaced
8 hours ago












$begingroup$
To add more detail to the question - the points are being generated by an optimization routine (NMaximize); I think the only way I can control for duplicates is by specifying a constraint on the ui, vi being generated.
$endgroup$
– spaced
7 hours ago




$begingroup$
To add more detail to the question - the points are being generated by an optimization routine (NMaximize); I think the only way I can control for duplicates is by specifying a constraint on the ui, vi being generated.
$endgroup$
– spaced
7 hours ago










4 Answers
4






active

oldest

votes


















4












$begingroup$

RandomSample[Tuples[Range[0, 20], 2], 10]



14, 13, 2, 17, 12, 7, 1, 11, 6, 6, 12, 4, 13, 14, 2,
16, 15, 6, 1, 0




Note: The length of the sample cannot exceed 21^2 (441).






share|improve this answer









$endgroup$




















    2












    $begingroup$

    Since you mentioned that your coordinates are drawn from integers in the regions 20 >= u >= 0 and 20 >= v >= 0, you can first generate a one-dimensional vector containing all lattice points:



    V = Flatten[Table[x[i,j],i,0,20,j,0,20]];


    Then you can select a random sample from this vector, e.g.:



    RandomSample[V,5]/.x->List



    16, 8, 10, 17, 8, 5, 0, 17, 16, 9




    Since V has no duplicates, the random sample will also contain no duplicates.






    share|improve this answer









    $endgroup$








    • 1




      $begingroup$
      Or even like this: RandomSample[Flatten[Table[x, y, x, 0, 20, y, 20], 1], 5].
      $endgroup$
      – kirma
      7 hours ago










    • $begingroup$
      Or... RandomSample[x, y /. Solve[(x | y) [Element] Integers, x, y [Element] Rectangle[0, 0, 20, 20]], 10]
      $endgroup$
      – kirma
      7 hours ago


















    2












    $begingroup$

    For 10 points, oversample and select unique ones using RandomSample.



    points = RandomInteger[20, 50, 2];
    points = RandomSample[points, 10]


    Actually, RandomInteger[20, 50, 2] appear to produce 50 unique 2D points.



    E.g.



    tries = 0;
    points = RandomInteger[20, 50, 2];
    While[(sample = Quiet[Check[RandomSample[points, 50], True]]),
    tries++;]
    tries



    0







    share|improve this answer











    $endgroup$








    • 1




      $begingroup$
      This doesn't guarantee success. A better approach is probably something like RandomSample[Range[0,20],10], right?
      $endgroup$
      – AccidentalFourierTransform
      7 hours ago











    • $begingroup$
      @spaced I'm not sure I understand your comment, but I feel that it changes the question considerably. It would be better if you were more specific in what you are trying to accomplish (and watch out for XY problems). Also, please edit any extra information directly into the OP rather than in a comment on an answer. Thanks!
      $endgroup$
      – AccidentalFourierTransform
      7 hours ago



















    1












    $begingroup$

    It kind of depends on what you want to do next. You only need to generate one such list, and only once? Then efficiency is not important, and so you can proceed very naively as follows: generate random lists until one works:



    Module[l = RandomInteger[0, 20, 10, 2],
    While[Length[l] != Length[DeleteDuplicates[l]],
    l = RandomInteger[0, 20, 10, 2]];
    l
    ]


    On the other hand, if you need many of these lists, then a more efficient approach is as follows: first generate all possible pairs, and pick a random sample ever time you need one such list:



    lists = Tuples[Range[0, 20], 2];
    sample := RandomSample[lists,10];


    Now every time you execute sample you will get one such list, picked at random.






    share|improve this answer









    $endgroup$













      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "387"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );






      spaced is a new contributor. Be nice, and check out our Code of Conduct.









      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f199522%2fhow-to-generate-random-points-without-duplication%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      4












      $begingroup$

      RandomSample[Tuples[Range[0, 20], 2], 10]



      14, 13, 2, 17, 12, 7, 1, 11, 6, 6, 12, 4, 13, 14, 2,
      16, 15, 6, 1, 0




      Note: The length of the sample cannot exceed 21^2 (441).






      share|improve this answer









      $endgroup$

















        4












        $begingroup$

        RandomSample[Tuples[Range[0, 20], 2], 10]



        14, 13, 2, 17, 12, 7, 1, 11, 6, 6, 12, 4, 13, 14, 2,
        16, 15, 6, 1, 0




        Note: The length of the sample cannot exceed 21^2 (441).






        share|improve this answer









        $endgroup$















          4












          4








          4





          $begingroup$

          RandomSample[Tuples[Range[0, 20], 2], 10]



          14, 13, 2, 17, 12, 7, 1, 11, 6, 6, 12, 4, 13, 14, 2,
          16, 15, 6, 1, 0




          Note: The length of the sample cannot exceed 21^2 (441).






          share|improve this answer









          $endgroup$



          RandomSample[Tuples[Range[0, 20], 2], 10]



          14, 13, 2, 17, 12, 7, 1, 11, 6, 6, 12, 4, 13, 14, 2,
          16, 15, 6, 1, 0




          Note: The length of the sample cannot exceed 21^2 (441).







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 7 hours ago









          kglrkglr

          195k10216439




          195k10216439





















              2












              $begingroup$

              Since you mentioned that your coordinates are drawn from integers in the regions 20 >= u >= 0 and 20 >= v >= 0, you can first generate a one-dimensional vector containing all lattice points:



              V = Flatten[Table[x[i,j],i,0,20,j,0,20]];


              Then you can select a random sample from this vector, e.g.:



              RandomSample[V,5]/.x->List



              16, 8, 10, 17, 8, 5, 0, 17, 16, 9




              Since V has no duplicates, the random sample will also contain no duplicates.






              share|improve this answer









              $endgroup$








              • 1




                $begingroup$
                Or even like this: RandomSample[Flatten[Table[x, y, x, 0, 20, y, 20], 1], 5].
                $endgroup$
                – kirma
                7 hours ago










              • $begingroup$
                Or... RandomSample[x, y /. Solve[(x | y) [Element] Integers, x, y [Element] Rectangle[0, 0, 20, 20]], 10]
                $endgroup$
                – kirma
                7 hours ago















              2












              $begingroup$

              Since you mentioned that your coordinates are drawn from integers in the regions 20 >= u >= 0 and 20 >= v >= 0, you can first generate a one-dimensional vector containing all lattice points:



              V = Flatten[Table[x[i,j],i,0,20,j,0,20]];


              Then you can select a random sample from this vector, e.g.:



              RandomSample[V,5]/.x->List



              16, 8, 10, 17, 8, 5, 0, 17, 16, 9




              Since V has no duplicates, the random sample will also contain no duplicates.






              share|improve this answer









              $endgroup$








              • 1




                $begingroup$
                Or even like this: RandomSample[Flatten[Table[x, y, x, 0, 20, y, 20], 1], 5].
                $endgroup$
                – kirma
                7 hours ago










              • $begingroup$
                Or... RandomSample[x, y /. Solve[(x | y) [Element] Integers, x, y [Element] Rectangle[0, 0, 20, 20]], 10]
                $endgroup$
                – kirma
                7 hours ago













              2












              2








              2





              $begingroup$

              Since you mentioned that your coordinates are drawn from integers in the regions 20 >= u >= 0 and 20 >= v >= 0, you can first generate a one-dimensional vector containing all lattice points:



              V = Flatten[Table[x[i,j],i,0,20,j,0,20]];


              Then you can select a random sample from this vector, e.g.:



              RandomSample[V,5]/.x->List



              16, 8, 10, 17, 8, 5, 0, 17, 16, 9




              Since V has no duplicates, the random sample will also contain no duplicates.






              share|improve this answer









              $endgroup$



              Since you mentioned that your coordinates are drawn from integers in the regions 20 >= u >= 0 and 20 >= v >= 0, you can first generate a one-dimensional vector containing all lattice points:



              V = Flatten[Table[x[i,j],i,0,20,j,0,20]];


              Then you can select a random sample from this vector, e.g.:



              RandomSample[V,5]/.x->List



              16, 8, 10, 17, 8, 5, 0, 17, 16, 9




              Since V has no duplicates, the random sample will also contain no duplicates.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered 7 hours ago









              KagaratschKagaratsch

              5,16941351




              5,16941351







              • 1




                $begingroup$
                Or even like this: RandomSample[Flatten[Table[x, y, x, 0, 20, y, 20], 1], 5].
                $endgroup$
                – kirma
                7 hours ago










              • $begingroup$
                Or... RandomSample[x, y /. Solve[(x | y) [Element] Integers, x, y [Element] Rectangle[0, 0, 20, 20]], 10]
                $endgroup$
                – kirma
                7 hours ago












              • 1




                $begingroup$
                Or even like this: RandomSample[Flatten[Table[x, y, x, 0, 20, y, 20], 1], 5].
                $endgroup$
                – kirma
                7 hours ago










              • $begingroup$
                Or... RandomSample[x, y /. Solve[(x | y) [Element] Integers, x, y [Element] Rectangle[0, 0, 20, 20]], 10]
                $endgroup$
                – kirma
                7 hours ago







              1




              1




              $begingroup$
              Or even like this: RandomSample[Flatten[Table[x, y, x, 0, 20, y, 20], 1], 5].
              $endgroup$
              – kirma
              7 hours ago




              $begingroup$
              Or even like this: RandomSample[Flatten[Table[x, y, x, 0, 20, y, 20], 1], 5].
              $endgroup$
              – kirma
              7 hours ago












              $begingroup$
              Or... RandomSample[x, y /. Solve[(x | y) [Element] Integers, x, y [Element] Rectangle[0, 0, 20, 20]], 10]
              $endgroup$
              – kirma
              7 hours ago




              $begingroup$
              Or... RandomSample[x, y /. Solve[(x | y) [Element] Integers, x, y [Element] Rectangle[0, 0, 20, 20]], 10]
              $endgroup$
              – kirma
              7 hours ago











              2












              $begingroup$

              For 10 points, oversample and select unique ones using RandomSample.



              points = RandomInteger[20, 50, 2];
              points = RandomSample[points, 10]


              Actually, RandomInteger[20, 50, 2] appear to produce 50 unique 2D points.



              E.g.



              tries = 0;
              points = RandomInteger[20, 50, 2];
              While[(sample = Quiet[Check[RandomSample[points, 50], True]]),
              tries++;]
              tries



              0







              share|improve this answer











              $endgroup$








              • 1




                $begingroup$
                This doesn't guarantee success. A better approach is probably something like RandomSample[Range[0,20],10], right?
                $endgroup$
                – AccidentalFourierTransform
                7 hours ago











              • $begingroup$
                @spaced I'm not sure I understand your comment, but I feel that it changes the question considerably. It would be better if you were more specific in what you are trying to accomplish (and watch out for XY problems). Also, please edit any extra information directly into the OP rather than in a comment on an answer. Thanks!
                $endgroup$
                – AccidentalFourierTransform
                7 hours ago
















              2












              $begingroup$

              For 10 points, oversample and select unique ones using RandomSample.



              points = RandomInteger[20, 50, 2];
              points = RandomSample[points, 10]


              Actually, RandomInteger[20, 50, 2] appear to produce 50 unique 2D points.



              E.g.



              tries = 0;
              points = RandomInteger[20, 50, 2];
              While[(sample = Quiet[Check[RandomSample[points, 50], True]]),
              tries++;]
              tries



              0







              share|improve this answer











              $endgroup$








              • 1




                $begingroup$
                This doesn't guarantee success. A better approach is probably something like RandomSample[Range[0,20],10], right?
                $endgroup$
                – AccidentalFourierTransform
                7 hours ago











              • $begingroup$
                @spaced I'm not sure I understand your comment, but I feel that it changes the question considerably. It would be better if you were more specific in what you are trying to accomplish (and watch out for XY problems). Also, please edit any extra information directly into the OP rather than in a comment on an answer. Thanks!
                $endgroup$
                – AccidentalFourierTransform
                7 hours ago














              2












              2








              2





              $begingroup$

              For 10 points, oversample and select unique ones using RandomSample.



              points = RandomInteger[20, 50, 2];
              points = RandomSample[points, 10]


              Actually, RandomInteger[20, 50, 2] appear to produce 50 unique 2D points.



              E.g.



              tries = 0;
              points = RandomInteger[20, 50, 2];
              While[(sample = Quiet[Check[RandomSample[points, 50], True]]),
              tries++;]
              tries



              0







              share|improve this answer











              $endgroup$



              For 10 points, oversample and select unique ones using RandomSample.



              points = RandomInteger[20, 50, 2];
              points = RandomSample[points, 10]


              Actually, RandomInteger[20, 50, 2] appear to produce 50 unique 2D points.



              E.g.



              tries = 0;
              points = RandomInteger[20, 50, 2];
              While[(sample = Quiet[Check[RandomSample[points, 50], True]]),
              tries++;]
              tries



              0








              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 7 hours ago

























              answered 8 hours ago









              Chris DegnenChris Degnen

              22.4k23787




              22.4k23787







              • 1




                $begingroup$
                This doesn't guarantee success. A better approach is probably something like RandomSample[Range[0,20],10], right?
                $endgroup$
                – AccidentalFourierTransform
                7 hours ago











              • $begingroup$
                @spaced I'm not sure I understand your comment, but I feel that it changes the question considerably. It would be better if you were more specific in what you are trying to accomplish (and watch out for XY problems). Also, please edit any extra information directly into the OP rather than in a comment on an answer. Thanks!
                $endgroup$
                – AccidentalFourierTransform
                7 hours ago













              • 1




                $begingroup$
                This doesn't guarantee success. A better approach is probably something like RandomSample[Range[0,20],10], right?
                $endgroup$
                – AccidentalFourierTransform
                7 hours ago











              • $begingroup$
                @spaced I'm not sure I understand your comment, but I feel that it changes the question considerably. It would be better if you were more specific in what you are trying to accomplish (and watch out for XY problems). Also, please edit any extra information directly into the OP rather than in a comment on an answer. Thanks!
                $endgroup$
                – AccidentalFourierTransform
                7 hours ago








              1




              1




              $begingroup$
              This doesn't guarantee success. A better approach is probably something like RandomSample[Range[0,20],10], right?
              $endgroup$
              – AccidentalFourierTransform
              7 hours ago





              $begingroup$
              This doesn't guarantee success. A better approach is probably something like RandomSample[Range[0,20],10], right?
              $endgroup$
              – AccidentalFourierTransform
              7 hours ago













              $begingroup$
              @spaced I'm not sure I understand your comment, but I feel that it changes the question considerably. It would be better if you were more specific in what you are trying to accomplish (and watch out for XY problems). Also, please edit any extra information directly into the OP rather than in a comment on an answer. Thanks!
              $endgroup$
              – AccidentalFourierTransform
              7 hours ago





              $begingroup$
              @spaced I'm not sure I understand your comment, but I feel that it changes the question considerably. It would be better if you were more specific in what you are trying to accomplish (and watch out for XY problems). Also, please edit any extra information directly into the OP rather than in a comment on an answer. Thanks!
              $endgroup$
              – AccidentalFourierTransform
              7 hours ago












              1












              $begingroup$

              It kind of depends on what you want to do next. You only need to generate one such list, and only once? Then efficiency is not important, and so you can proceed very naively as follows: generate random lists until one works:



              Module[l = RandomInteger[0, 20, 10, 2],
              While[Length[l] != Length[DeleteDuplicates[l]],
              l = RandomInteger[0, 20, 10, 2]];
              l
              ]


              On the other hand, if you need many of these lists, then a more efficient approach is as follows: first generate all possible pairs, and pick a random sample ever time you need one such list:



              lists = Tuples[Range[0, 20], 2];
              sample := RandomSample[lists,10];


              Now every time you execute sample you will get one such list, picked at random.






              share|improve this answer









              $endgroup$

















                1












                $begingroup$

                It kind of depends on what you want to do next. You only need to generate one such list, and only once? Then efficiency is not important, and so you can proceed very naively as follows: generate random lists until one works:



                Module[l = RandomInteger[0, 20, 10, 2],
                While[Length[l] != Length[DeleteDuplicates[l]],
                l = RandomInteger[0, 20, 10, 2]];
                l
                ]


                On the other hand, if you need many of these lists, then a more efficient approach is as follows: first generate all possible pairs, and pick a random sample ever time you need one such list:



                lists = Tuples[Range[0, 20], 2];
                sample := RandomSample[lists,10];


                Now every time you execute sample you will get one such list, picked at random.






                share|improve this answer









                $endgroup$















                  1












                  1








                  1





                  $begingroup$

                  It kind of depends on what you want to do next. You only need to generate one such list, and only once? Then efficiency is not important, and so you can proceed very naively as follows: generate random lists until one works:



                  Module[l = RandomInteger[0, 20, 10, 2],
                  While[Length[l] != Length[DeleteDuplicates[l]],
                  l = RandomInteger[0, 20, 10, 2]];
                  l
                  ]


                  On the other hand, if you need many of these lists, then a more efficient approach is as follows: first generate all possible pairs, and pick a random sample ever time you need one such list:



                  lists = Tuples[Range[0, 20], 2];
                  sample := RandomSample[lists,10];


                  Now every time you execute sample you will get one such list, picked at random.






                  share|improve this answer









                  $endgroup$



                  It kind of depends on what you want to do next. You only need to generate one such list, and only once? Then efficiency is not important, and so you can proceed very naively as follows: generate random lists until one works:



                  Module[l = RandomInteger[0, 20, 10, 2],
                  While[Length[l] != Length[DeleteDuplicates[l]],
                  l = RandomInteger[0, 20, 10, 2]];
                  l
                  ]


                  On the other hand, if you need many of these lists, then a more efficient approach is as follows: first generate all possible pairs, and pick a random sample ever time you need one such list:



                  lists = Tuples[Range[0, 20], 2];
                  sample := RandomSample[lists,10];


                  Now every time you execute sample you will get one such list, picked at random.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 7 hours ago









                  AccidentalFourierTransformAccidentalFourierTransform

                  5,55511142




                  5,55511142




















                      spaced is a new contributor. Be nice, and check out our Code of Conduct.









                      draft saved

                      draft discarded


















                      spaced is a new contributor. Be nice, and check out our Code of Conduct.












                      spaced is a new contributor. Be nice, and check out our Code of Conduct.











                      spaced is a new contributor. Be nice, and check out our Code of Conduct.














                      Thanks for contributing an answer to Mathematica Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      Use MathJax to format equations. MathJax reference.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f199522%2fhow-to-generate-random-points-without-duplication%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                      Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                      François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480