The intended behaviour of the stores is: Always keep the staples in stock, and then include normal_stock_min to normal_stock_max other items.  This code will always keep the staples in stock and then will top up so the store has at most normal_stock_max items.  e.g. for the general store, it has 0-4 slots for non-staples items.  This code should guarantee then that the store will never generate any random other items because the stock will always be at least 9 items when this bit of code it called (because the staple generation is above this).