help with logic

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ritvik
    New Member
    • May 2007
    • 8

    help with logic

    hi
    i am required to generate two independent data sets using random numbers.
    1) first(lot sizes) can be generated with no problem.
    2) second set(order size) of data should be such that the total of second is less than or equal to the total of one.
    order size <= lot size
  • svlsr2000
    Recognized Expert New Member
    • Feb 2007
    • 181

    #2
    You can use combination of srand and rand.

    Srand is used to seed the random number generator.

    Do both of them simultaneously and make sure Your secod random number is always smaller then first one before adding to repository or database.

    int array1[100];
    int array2[100];
    int index;
    srand(...);
    ....
    array1[index] = rand();
    array2[index] = rand()
    if(array1[index]<array2[index])
    {
    swap(array1[index], array2[index]);
    }

    Comment

    • ritvik
      New Member
      • May 2007
      • 8

      #3
      Thanx alot. i am using rand nad srand
      but i canot take this condition. one is the lot size that let us say there are 3 lots
      l1 =20 ; l2= 30; l3=15
      there can be different orders like
      o1 =5 o2 = 10 or=40 o4=5 o5=10
      i have to generate the order sizes so that they can be staisfied with the total lot size. they cannot be generated simultaneously the way you said.
      thanx once again but can u help in this condition.


      Originally posted by svlsr2000
      You can use combination of srand and rand.

      Srand is used to seed the random number generator.

      Do both of them simultaneously and make sure Your secod random number is always smaller then first one before adding to repository or database.

      int array1[100];
      int array2[100];
      int index;
      srand(...);
      ....
      array1[index] = rand();
      array2[index] = rand()
      if(array1[index]<array2[index])
      {
      swap(array1[index], array2[index]);
      }

      Comment

      • svlsr2000
        Recognized Expert New Member
        • Feb 2007
        • 181

        #4
        What are the different conditions and how los do You have? Can you be more precise in your input?

        Comment

        • ritvik
          New Member
          • May 2007
          • 8

          #5
          Originally posted by svlsr2000
          What are the different conditions and how los do You have? Can you be more precise in your input?
          i have specified my onlly condiiton. actually i have to generate data for experimentation .
          i am required to ask
          1)the total number of lots being processed
          2) the total number of parallel facilities
          3) and the order for each parallel facility from the user.
          for e.g user enters 4 lots; 2 parallel facilities and 2 orders for the first facility
          3 orders for the second facility.
          then i have to generate 4 lot sizes, letus say : 20, 12, 23, 5.
          (any value between 2 and 25)
          then i hv to generate 5 order sizes(2 for facility 1 and 3 for facility 2)
          100,34,23,5,6.
          the generation is not fully independent because the total order size should be less tahn or equal to the total lot size so that all orders can be satisfied.
          this is the problem.
          thanx for your time and effort.
          bye
          thannx

          Comment

          • ritvik
            New Member
            • May 2007
            • 8

            #6
            hey what happened all you programmers no solution to this problem

            Comment

            Working...