Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 string generator
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 Wink | ;)
Posted 9-Aug-12 8:53am
po17251.6K
Edited 9-Aug-12 9:04am
v2
Comments
Sergey Alexandrovich Kryukov at 9-Aug-12 16:14pm
   
Why?
--SA
Volynsky Alex at 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 uniqueRandomGenerator(int minVal, int maxVal)
{
Random rand = new Random();
SortedList uniqueList = new SortedList();
for (int i = minVal; i <= maxVal; i++)
uniqueList.Add(rand.Next(), i);
 
return uniqueList.Values.ToList();
}
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

All you need is a List(of Food) and a Random function... Besides you didnt tag the question on what languange you use....
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Comments
po1725123 at 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 at 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 at 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 at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 334
1 Kornfeld Eliyahu Peter 325
2 Maciej Los 239
3 OriginalGriff 188
4 King Fisher 185
0 OriginalGriff 6,303
1 DamithSL 4,764
2 Maciej Los 4,306
3 Kornfeld Eliyahu Peter 3,914
4 Sergey Alexandrovich Kryukov 3,538


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 9 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100