An algorithm for finding a random integer

what are the combinations of 10 random integers from 1 to 100, and then 100?

May.20,2022

according to the way of the main sentence, we tend to random 10 numbers from 1 to 100, and then find out the combination of 10 random numbers with a sum of 100.
then

import random
from itertools import combinations

rd = random.sample(range(1, 101), 10)
-sharp 10
comb = [j for i in range(1, 11) for j in combinations(rd, i) if sum(j) == 100]
print(rd)
print(comb)

if it is a combination of 10 out of 100 and 100, the combination is more, and violence is not advisable.

def get_combs(n=100, k=10, tg=100):
    combs = []
    x = tg - sum(range(1, k))

    def dfs(comb, idx=0, k=k, t=tg):
        dmx = min(tg - sum(comb), x, n)
        arr = range(1, dmx + 1)
        if t == 0 and k == 0:
            combs.append(comb[:])
            return
        if dmx <= idx or k < 0 or t < 0:
            return
        for i in range(idx, dmx):
            v = arr[i]
            dfs(comb + [v], i + 1, k - 1, t - v)

    dfs([])

    return combs

-sharp coding: utf-8

import random

def combinationSum2(candidates, target):
    res = []
    can = sorted(candidates)

    def dfs(comb, s, i):
        while i < len(can):
            if can[i] + s > target:
                return
            elif can[i] + s == target:
                if (comb + [can[i]]) not in res:
                    res.append(comb + [can[i]])
            else:
                dfs(comb + [can[i]], s + can[i], i + 1)
            i += 1

    dfs([], 0, 0)
    return res

-sharp1-10010
lst = random.sample(range(1, 101), 10)
-sharp100
print combinationSum2(lst, 100)

  

it's not random, it's permutation, isn't it?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b1ce-2c24b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b1ce-2c24b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?