Sum of Random Integers

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I am trying to get a list of numbers with at least 1000 sums as possible, using random numbers from 1 to 10. But I don't want to get blank list output.



How can I only get a list of numbers greater than 1000 in total?
I think my loop is insufficient.



Here is my code:



m = ;
n = RandomInteger[1, 10, 170];
liste = Total[n];
While[liste >= 1000, AppendTo[m, n]; Break;]
m
liste









share|improve this question







New contributor




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















  • 2




    Yes, I think your loop is insufficient, too :) It's not perfectly clear to me what you want, but maybe it's this?: While[n = RandomInteger[1, 10, 170]; Total[n] < 1000,]; n
    – Michael E2
    3 hours ago











  • RandomInteger[1, 10, 1000] is guaranteed to work.
    – AccidentalFourierTransform
    2 hours ago










  • Or: Reap[sum = 0; While[sum < 1000, sum += (n = RandomInteger[1, 10]); Sow[n]]][[2, 1]]
    – Daniel Lichtblau
    2 hours ago














up vote
2
down vote

favorite












I am trying to get a list of numbers with at least 1000 sums as possible, using random numbers from 1 to 10. But I don't want to get blank list output.



How can I only get a list of numbers greater than 1000 in total?
I think my loop is insufficient.



Here is my code:



m = ;
n = RandomInteger[1, 10, 170];
liste = Total[n];
While[liste >= 1000, AppendTo[m, n]; Break;]
m
liste









share|improve this question







New contributor




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















  • 2




    Yes, I think your loop is insufficient, too :) It's not perfectly clear to me what you want, but maybe it's this?: While[n = RandomInteger[1, 10, 170]; Total[n] < 1000,]; n
    – Michael E2
    3 hours ago











  • RandomInteger[1, 10, 1000] is guaranteed to work.
    – AccidentalFourierTransform
    2 hours ago










  • Or: Reap[sum = 0; While[sum < 1000, sum += (n = RandomInteger[1, 10]); Sow[n]]][[2, 1]]
    – Daniel Lichtblau
    2 hours ago












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I am trying to get a list of numbers with at least 1000 sums as possible, using random numbers from 1 to 10. But I don't want to get blank list output.



How can I only get a list of numbers greater than 1000 in total?
I think my loop is insufficient.



Here is my code:



m = ;
n = RandomInteger[1, 10, 170];
liste = Total[n];
While[liste >= 1000, AppendTo[m, n]; Break;]
m
liste









share|improve this question







New contributor




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











I am trying to get a list of numbers with at least 1000 sums as possible, using random numbers from 1 to 10. But I don't want to get blank list output.



How can I only get a list of numbers greater than 1000 in total?
I think my loop is insufficient.



Here is my code:



m = ;
n = RandomInteger[1, 10, 170];
liste = Total[n];
While[liste >= 1000, AppendTo[m, n]; Break;]
m
liste






random education infinite-loop






share|improve this question







New contributor




ithilquessirr 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




ithilquessirr 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






New contributor




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









asked 3 hours ago









ithilquessirr

132




132




New contributor




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





New contributor





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






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







  • 2




    Yes, I think your loop is insufficient, too :) It's not perfectly clear to me what you want, but maybe it's this?: While[n = RandomInteger[1, 10, 170]; Total[n] < 1000,]; n
    – Michael E2
    3 hours ago











  • RandomInteger[1, 10, 1000] is guaranteed to work.
    – AccidentalFourierTransform
    2 hours ago










  • Or: Reap[sum = 0; While[sum < 1000, sum += (n = RandomInteger[1, 10]); Sow[n]]][[2, 1]]
    – Daniel Lichtblau
    2 hours ago












  • 2




    Yes, I think your loop is insufficient, too :) It's not perfectly clear to me what you want, but maybe it's this?: While[n = RandomInteger[1, 10, 170]; Total[n] < 1000,]; n
    – Michael E2
    3 hours ago











  • RandomInteger[1, 10, 1000] is guaranteed to work.
    – AccidentalFourierTransform
    2 hours ago










  • Or: Reap[sum = 0; While[sum < 1000, sum += (n = RandomInteger[1, 10]); Sow[n]]][[2, 1]]
    – Daniel Lichtblau
    2 hours ago







2




2




Yes, I think your loop is insufficient, too :) It's not perfectly clear to me what you want, but maybe it's this?: While[n = RandomInteger[1, 10, 170]; Total[n] < 1000,]; n
– Michael E2
3 hours ago





Yes, I think your loop is insufficient, too :) It's not perfectly clear to me what you want, but maybe it's this?: While[n = RandomInteger[1, 10, 170]; Total[n] < 1000,]; n
– Michael E2
3 hours ago













RandomInteger[1, 10, 1000] is guaranteed to work.
– AccidentalFourierTransform
2 hours ago




RandomInteger[1, 10, 1000] is guaranteed to work.
– AccidentalFourierTransform
2 hours ago












Or: Reap[sum = 0; While[sum < 1000, sum += (n = RandomInteger[1, 10]); Sow[n]]][[2, 1]]
– Daniel Lichtblau
2 hours ago




Or: Reap[sum = 0; While[sum < 1000, sum += (n = RandomInteger[1, 10]); Sow[n]]][[2, 1]]
– Daniel Lichtblau
2 hours ago










3 Answers
3






active

oldest

votes

















up vote
2
down vote



accepted










if you want to output just one number with your conditions try



liste = 0;
While[liste < 1000, n = RandomInteger[1, 10, 170];
liste = Total[n]]
liste
n


here is the result and the 170 numbers that add up to this result

If you don't want all these numbers to be displayed, just remove the last n from the code




1020



4,4,10,4,4,9,9,4,2,2,10,8,8,2,2,1,3,6,3,8,7,8,4,1,6,1,5,3,9,9,1,9,2,3,10,10,3,10,6,10,10,9,10,10,2,6,7,1,5,9,8,5,3,8,10,8,1,1,10,6,7,10,3,7,7,5,9,3,10,10,6,6,5,3,9,10,1,8,1,8,4,9,1,4,9,8,7,2,9,5,6,3,10,10,10,5,3,6,6,4,1,10,3,4,10,4,10,5,10,10,5,5,9,1,10,5,9,5,5,5,7,8,1,3,2,8,10,9,9,6,2,9,5,5,6,10,1,5,7,7,7,3,7,7,4,10,5,8,2,1,8,9,8,2,5,10,1,2,7,9,8,9,3,8,8,3,10,2,6,4







share|improve this answer





























    up vote
    1
    down vote













    var = Array[x, 170];

    dud = DiscreteUniformDistribution[1, 10];


    Since you want the sum (Total) of the 170 variables to be at least 1000 and the most the sum could be is 1700, then the distribution for the truncated sum is



    dist = TruncatedDistribution[1000, 1700,
    TransformedDistribution[Total[var],
    Thread[Distributed[var, dud]]]];


    To get a list of 1000 random draws from this distribution



    SeedRandom[0]

    list = RandomVariate[dist, 1000];

    Mean[list] // N

    (* 1015.98 *)

    Median[list]

    (* 1012 *)

    Histogram[list]


    enter image description here






    share|improve this answer



























      up vote
      0
      down vote













      One way of looking at your problem could be in terms of making a series of experiment. Then understanding the likelihood that the sum of 170 integers is greater than 1000. The code would then be:



      res = Table[i, RandomVariate[DiscreteUniformDistribution[1, 10], 170], i,
      1, 100];
      Select[(Total@#[[2]]) >= 1000 &]@ res





      share|improve this answer




















        Your Answer





        StackExchange.ifUsing("editor", function ()
        return StackExchange.using("mathjaxEditing", function ()
        StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
        StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
        );
        );
        , "mathjax-editing");

        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',
        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
        );



        );






        ithilquessirr 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%2f185267%2fsum-of-random-integers%23new-answer', 'question_page');

        );

        Post as a guest






























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        2
        down vote



        accepted










        if you want to output just one number with your conditions try



        liste = 0;
        While[liste < 1000, n = RandomInteger[1, 10, 170];
        liste = Total[n]]
        liste
        n


        here is the result and the 170 numbers that add up to this result

        If you don't want all these numbers to be displayed, just remove the last n from the code




        1020



        4,4,10,4,4,9,9,4,2,2,10,8,8,2,2,1,3,6,3,8,7,8,4,1,6,1,5,3,9,9,1,9,2,3,10,10,3,10,6,10,10,9,10,10,2,6,7,1,5,9,8,5,3,8,10,8,1,1,10,6,7,10,3,7,7,5,9,3,10,10,6,6,5,3,9,10,1,8,1,8,4,9,1,4,9,8,7,2,9,5,6,3,10,10,10,5,3,6,6,4,1,10,3,4,10,4,10,5,10,10,5,5,9,1,10,5,9,5,5,5,7,8,1,3,2,8,10,9,9,6,2,9,5,5,6,10,1,5,7,7,7,3,7,7,4,10,5,8,2,1,8,9,8,2,5,10,1,2,7,9,8,9,3,8,8,3,10,2,6,4







        share|improve this answer


























          up vote
          2
          down vote



          accepted










          if you want to output just one number with your conditions try



          liste = 0;
          While[liste < 1000, n = RandomInteger[1, 10, 170];
          liste = Total[n]]
          liste
          n


          here is the result and the 170 numbers that add up to this result

          If you don't want all these numbers to be displayed, just remove the last n from the code




          1020



          4,4,10,4,4,9,9,4,2,2,10,8,8,2,2,1,3,6,3,8,7,8,4,1,6,1,5,3,9,9,1,9,2,3,10,10,3,10,6,10,10,9,10,10,2,6,7,1,5,9,8,5,3,8,10,8,1,1,10,6,7,10,3,7,7,5,9,3,10,10,6,6,5,3,9,10,1,8,1,8,4,9,1,4,9,8,7,2,9,5,6,3,10,10,10,5,3,6,6,4,1,10,3,4,10,4,10,5,10,10,5,5,9,1,10,5,9,5,5,5,7,8,1,3,2,8,10,9,9,6,2,9,5,5,6,10,1,5,7,7,7,3,7,7,4,10,5,8,2,1,8,9,8,2,5,10,1,2,7,9,8,9,3,8,8,3,10,2,6,4







          share|improve this answer
























            up vote
            2
            down vote



            accepted







            up vote
            2
            down vote



            accepted






            if you want to output just one number with your conditions try



            liste = 0;
            While[liste < 1000, n = RandomInteger[1, 10, 170];
            liste = Total[n]]
            liste
            n


            here is the result and the 170 numbers that add up to this result

            If you don't want all these numbers to be displayed, just remove the last n from the code




            1020



            4,4,10,4,4,9,9,4,2,2,10,8,8,2,2,1,3,6,3,8,7,8,4,1,6,1,5,3,9,9,1,9,2,3,10,10,3,10,6,10,10,9,10,10,2,6,7,1,5,9,8,5,3,8,10,8,1,1,10,6,7,10,3,7,7,5,9,3,10,10,6,6,5,3,9,10,1,8,1,8,4,9,1,4,9,8,7,2,9,5,6,3,10,10,10,5,3,6,6,4,1,10,3,4,10,4,10,5,10,10,5,5,9,1,10,5,9,5,5,5,7,8,1,3,2,8,10,9,9,6,2,9,5,5,6,10,1,5,7,7,7,3,7,7,4,10,5,8,2,1,8,9,8,2,5,10,1,2,7,9,8,9,3,8,8,3,10,2,6,4







            share|improve this answer














            if you want to output just one number with your conditions try



            liste = 0;
            While[liste < 1000, n = RandomInteger[1, 10, 170];
            liste = Total[n]]
            liste
            n


            here is the result and the 170 numbers that add up to this result

            If you don't want all these numbers to be displayed, just remove the last n from the code




            1020



            4,4,10,4,4,9,9,4,2,2,10,8,8,2,2,1,3,6,3,8,7,8,4,1,6,1,5,3,9,9,1,9,2,3,10,10,3,10,6,10,10,9,10,10,2,6,7,1,5,9,8,5,3,8,10,8,1,1,10,6,7,10,3,7,7,5,9,3,10,10,6,6,5,3,9,10,1,8,1,8,4,9,1,4,9,8,7,2,9,5,6,3,10,10,10,5,3,6,6,4,1,10,3,4,10,4,10,5,10,10,5,5,9,1,10,5,9,5,5,5,7,8,1,3,2,8,10,9,9,6,2,9,5,5,6,10,1,5,7,7,7,3,7,7,4,10,5,8,2,1,8,9,8,2,5,10,1,2,7,9,8,9,3,8,8,3,10,2,6,4








            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 2 hours ago

























            answered 2 hours ago









            J42161217

            2,417218




            2,417218




















                up vote
                1
                down vote













                var = Array[x, 170];

                dud = DiscreteUniformDistribution[1, 10];


                Since you want the sum (Total) of the 170 variables to be at least 1000 and the most the sum could be is 1700, then the distribution for the truncated sum is



                dist = TruncatedDistribution[1000, 1700,
                TransformedDistribution[Total[var],
                Thread[Distributed[var, dud]]]];


                To get a list of 1000 random draws from this distribution



                SeedRandom[0]

                list = RandomVariate[dist, 1000];

                Mean[list] // N

                (* 1015.98 *)

                Median[list]

                (* 1012 *)

                Histogram[list]


                enter image description here






                share|improve this answer
























                  up vote
                  1
                  down vote













                  var = Array[x, 170];

                  dud = DiscreteUniformDistribution[1, 10];


                  Since you want the sum (Total) of the 170 variables to be at least 1000 and the most the sum could be is 1700, then the distribution for the truncated sum is



                  dist = TruncatedDistribution[1000, 1700,
                  TransformedDistribution[Total[var],
                  Thread[Distributed[var, dud]]]];


                  To get a list of 1000 random draws from this distribution



                  SeedRandom[0]

                  list = RandomVariate[dist, 1000];

                  Mean[list] // N

                  (* 1015.98 *)

                  Median[list]

                  (* 1012 *)

                  Histogram[list]


                  enter image description here






                  share|improve this answer






















                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    var = Array[x, 170];

                    dud = DiscreteUniformDistribution[1, 10];


                    Since you want the sum (Total) of the 170 variables to be at least 1000 and the most the sum could be is 1700, then the distribution for the truncated sum is



                    dist = TruncatedDistribution[1000, 1700,
                    TransformedDistribution[Total[var],
                    Thread[Distributed[var, dud]]]];


                    To get a list of 1000 random draws from this distribution



                    SeedRandom[0]

                    list = RandomVariate[dist, 1000];

                    Mean[list] // N

                    (* 1015.98 *)

                    Median[list]

                    (* 1012 *)

                    Histogram[list]


                    enter image description here






                    share|improve this answer












                    var = Array[x, 170];

                    dud = DiscreteUniformDistribution[1, 10];


                    Since you want the sum (Total) of the 170 variables to be at least 1000 and the most the sum could be is 1700, then the distribution for the truncated sum is



                    dist = TruncatedDistribution[1000, 1700,
                    TransformedDistribution[Total[var],
                    Thread[Distributed[var, dud]]]];


                    To get a list of 1000 random draws from this distribution



                    SeedRandom[0]

                    list = RandomVariate[dist, 1000];

                    Mean[list] // N

                    (* 1015.98 *)

                    Median[list]

                    (* 1012 *)

                    Histogram[list]


                    enter image description here







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 2 hours ago









                    Bob Hanlon

                    56.6k23591




                    56.6k23591




















                        up vote
                        0
                        down vote













                        One way of looking at your problem could be in terms of making a series of experiment. Then understanding the likelihood that the sum of 170 integers is greater than 1000. The code would then be:



                        res = Table[i, RandomVariate[DiscreteUniformDistribution[1, 10], 170], i,
                        1, 100];
                        Select[(Total@#[[2]]) >= 1000 &]@ res





                        share|improve this answer
























                          up vote
                          0
                          down vote













                          One way of looking at your problem could be in terms of making a series of experiment. Then understanding the likelihood that the sum of 170 integers is greater than 1000. The code would then be:



                          res = Table[i, RandomVariate[DiscreteUniformDistribution[1, 10], 170], i,
                          1, 100];
                          Select[(Total@#[[2]]) >= 1000 &]@ res





                          share|improve this answer






















                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            One way of looking at your problem could be in terms of making a series of experiment. Then understanding the likelihood that the sum of 170 integers is greater than 1000. The code would then be:



                            res = Table[i, RandomVariate[DiscreteUniformDistribution[1, 10], 170], i,
                            1, 100];
                            Select[(Total@#[[2]]) >= 1000 &]@ res





                            share|improve this answer












                            One way of looking at your problem could be in terms of making a series of experiment. Then understanding the likelihood that the sum of 170 integers is greater than 1000. The code would then be:



                            res = Table[i, RandomVariate[DiscreteUniformDistribution[1, 10], 170], i,
                            1, 100];
                            Select[(Total@#[[2]]) >= 1000 &]@ res






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 1 hour ago









                            FredrikD

                            8071822




                            8071822




















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









                                 

                                draft saved


                                draft discarded


















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












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











                                ithilquessirr 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%2f185267%2fsum-of-random-integers%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Comments

                                Popular posts from this blog

                                What does second last employer means? [closed]

                                List of Gilmore Girls characters

                                Confectionery