I would like to generate a random table (type and quantity) with two conditions
generating should end after qty (quantity) is not bigger than total sum (total)
and every row should have include unique value in type.
total = 20
qty = c(2,3,4,5)
type = c(1:270)
gen.table = data.frame(type = integer(), qty = integer())
gen.table[1, ] = c(NA,1)
for (j in 1:total) {
while(sum(gen.table[1:j,][["qty"]]) <= total){
sb = sample(type, 1)
gen.table[j,][["type"]] = sb
type = type[!type %in% sb]
gen.table[j,][["qty"]] = sample(qty, 1)
}
}
But after first iteration vectror of types is empty