Sum of Random Integers
Clash 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
random education infinite-loop
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.
add a comment |Â
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
random education infinite-loop
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
add a comment |Â
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
random education infinite-loop
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
random education infinite-loop
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.
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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]
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
edited 2 hours ago
answered 2 hours ago


J42161217
2,417218
2,417218
add a comment |Â
add a comment |Â
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]
add a comment |Â
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]
add a comment |Â
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]
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]
answered 2 hours ago
Bob Hanlon
56.6k23591
56.6k23591
add a comment |Â
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered 1 hour ago
FredrikD
8071822
8071822
add a comment |Â
add a comment |Â
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.
ithilquessirr is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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