Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hello
I wonder how a program in C# that could produce food for a week but never repeated.
will generate input, meat, fish and dessert for each day of the week.

eg:
Monday Tuesday Wednesday Thursday Friday Saturday Sunday
bread ... ... ... ... ... ...
chicken ... ... ... ... ... ...
sardines ... ... ... ... ... ...
pineapple ... ... ... ... ... ...

Thank you already ;)
Posted
Updated 9-Aug-12 8:04am
v2
Comments
Sergey Alexandrovich Kryukov 9-Aug-12 16:14pm    
Why?
--SA
Volynsky Alex 10-Aug-12 4:22am    
it mean you want generate random numbers (in range 1-7) with no repeat in c#?

How about:
public List<int> uniqueRandomGenerator(int minVal, int maxVal)
{
Random rand = new Random();
SortedList<int, int=""> uniqueList = new SortedList<int, int="">();
for (int i = minVal; i <= maxVal; i++)
uniqueList.Add(rand.Next(), i);

return uniqueList.Values.ToList();
}

All you need is a List(of Food) and a Random function... Besides you didnt tag the question on what languange you use....
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 9-Aug-12 16:11pm    
Eating random food? No, thank you. :-)
Besides, OP's requirement "never repeated" makes no sense. Actually, both random menu and "never repeated" menu are both total absurd, just a useless exercise...
--SA
I'm going to expand on what Kenneth said, adding that as a food is used, remove it from the list, so it is never repeated.
 
Share this answer
 
Comments
po1725 9-Aug-12 14:13pm    
hi I already have all the food in the database, if I remove from the list i can not re-use then.
could show some examples how I can generate strings without repeating? I found nothing
wizardzz 9-Aug-12 14:22pm    
Just one way: Load from Database to a 'working' list that they are selected and removed from, reload the list every week.

Or once selected, add to list. Then only select from database if not included in 'used' list.

There are many ways to do this.
Kenneth Haugland 9-Aug-12 14:28pm    
LOL... Im sorry but the comment "I have all the food i need in the database" did me in.

If you allow the to be reused only not with the same dessert etc, we are talking heavy combinatorics and statistics, making the problem even wors to deal with. But I could easily predict how many variations that there would be, and the used combination could be stored in the database :-)

But Im not going to write that and give it over ....
Sergey Alexandrovich Kryukov 9-Aug-12 16:14pm    
This is not an expansion, but a solution (and random menu is not a solution). My 5.
However, the whole problem looks absurd to me (see my comment to Solution 1).
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900