Algorithms for randomized time-varying knapsack problems