Post History
C (gcc), 48 43 bytes s;r(n,m){s+=rand()%m+1;return--n?r(n,m):s;} Try it online! Previous 48 bytes version using loop: i,s;r(n,m){for(;i<n;i++)s+=rand()%m+1;return s;}
Answer
#3: Post edited
# [C (gcc)], <del>48</del> 45 bytes- <!-- language-all: lang-c -->
i,s;r(n,m){s+=rand()%m+1;return--n?r(n,m):s;}[Try it online!][TIO-l3si606q]- [C (gcc)]: https://gcc.gnu.org/
[TIO-l3si606q]: https://tio.run/##VY29DsIgFEZ3noLUNIEUjDo4FH9exKUC6k3KrblQl6bPjkUH43rO@fJZfbc2rwBtPzrPDzG5Hq7rx4n9WILg/8lSwVBQBhUNCVRBTrE5UodOyDo0W0M@jYRa4/mr22jmDJh46AC5eA3gJJsY5/EzKh9iI6VZyJOW7iaq2l2wUpzETu2LmfMb "C (gcc) – Try It Online"- ---
- Previous 48 bytes version using loop:
- `i,s;r(n,m){for(;i<n;i++)s+=rand()%m+1;return s;}`
- # [C (gcc)], <del>48</del> 43 bytes
- <!-- language-all: lang-c -->
- s;r(n,m){s+=rand()%m+1;return--n?r(n,m):s;}
- [Try it online!][TIO-l3sib2ai]
- [C (gcc)]: https://gcc.gnu.org/
- [TIO-l3sib2ai]: https://tio.run/##VY29DsIgFEZ3noLUNLmkYNTBofjzIi4VUG9Sbg1Ql6bPjkUH43rO@fIZdTcmr5BMP1rHDzHZHq/rx4n9WELv/slS4VBQjjoASS@m2BxDRxZE7ZutDi6NgZSi81e3Uc8ZKXHfIXF4DWgFmxjn8TMqD7ARQi/kGZbuBlVtL1RJHmAn98XM@Q0 "C (gcc) – Try It Online"
- ---
- Previous 48 bytes version using loop:
- `i,s;r(n,m){for(;i<n;i++)s+=rand()%m+1;return s;}`
#2: Post edited
# [C (gcc)], 48 bytes- <!-- language-all: lang-c -->
i,s;r(n,m){for(;i<n;i++)s+=rand()%m+1;return s;}[Try it online!][TIO-l3shtp7u]- [C (gcc)]: https://gcc.gnu.org/
[TIO-l3shtp7u]: https://tio.run/##Vc1BDoIwEIXhPaeYYEimaTWycVP0JG6wBZ2EDmRa3BDOXsGNcfu9P3nu@HQuH4jdMPsOmpj8QI/T61b8LFHo/mWraNwpk4lWkE1QSz8KWmrYktYq6qu07FFVQddWujQLQ7RrJk4QWmLA90heFUsBEL/pfoNnpewmk2xdj2Xl71waEKzNZV/W/AE "C (gcc) – Try It Online"Not a lot of ways to make it more compact in C (gcc). Pass by reference version yielded same symbol count:`i;r(n,m,int*q){for(*q=0;i<n;i++)*q+=rand()%m+1;}`This would also work but also same count:`i,s;r(n,m){for(;i<n;i++)s+=rand()%m;return s+n;}`
- # [C (gcc)], <del>48</del> 45 bytes
- <!-- language-all: lang-c -->
- i,s;r(n,m){s+=rand()%m+1;return--n?r(n,m):s;}
- [Try it online!][TIO-l3si606q]
- [C (gcc)]: https://gcc.gnu.org/
- [TIO-l3si606q]: https://tio.run/##VY29DsIgFEZ3noLUNIEUjDo4FH9exKUC6k3KrblQl6bPjkUH43rO@fJZfbc2rwBtPzrPDzG5Hq7rx4n9WILg/8lSwVBQBhUNCVRBTrE5UodOyDo0W0M@jYRa4/mr22jmDJh46AC5eA3gJJsY5/EzKh9iI6VZyJOW7iaq2l2wUpzETu2LmfMb "C (gcc) – Try It Online"
- ---
- Previous 48 bytes version using loop:
- `i,s;r(n,m){for(;i<n;i++)s+=rand()%m+1;return s;}`
#1: Initial revision
# [C (gcc)], 48 bytes <!-- language-all: lang-c --> i,s;r(n,m){for(;i<n;i++)s+=rand()%m+1;return s;} [Try it online!][TIO-l3shtp7u] [C (gcc)]: https://gcc.gnu.org/ [TIO-l3shtp7u]: https://tio.run/##Vc1BDoIwEIXhPaeYYEimaTWycVP0JG6wBZ2EDmRa3BDOXsGNcfu9P3nu@HQuH4jdMPsOmpj8QI/T61b8LFHo/mWraNwpk4lWkE1QSz8KWmrYktYq6qu07FFVQddWujQLQ7RrJk4QWmLA90heFUsBEL/pfoNnpewmk2xdj2Xl71waEKzNZV/W/AE "C (gcc) – Try It Online" Not a lot of ways to make it more compact in C (gcc). Pass by reference version yielded same symbol count: `i;r(n,m,int*q){for(*q=0;i<n;i++)*q+=rand()%m+1;}` This would also work but also same count: `i,s;r(n,m){for(;i<n;i++)s+=rand()%m;return s+n;}`