Satish Hirpara

Satish Hirpara

  • 1.5k
  • 256
  • 42.1k

Generate Random Numbers with Predefined Sum

Apr 23 2013 10:22 AM
Hello ,

I have the following question:


2000 ltr Water tank needs to be filled up with 1000 entries only . so for this 
AS A INPUT : - 
 I need to generate 1000 Random Numbers with in a range 0.5 to 3.0 in such a way that total of this number is 2000.0
Now when this 1000 random numbers gets generated , 


AS A OUTPUT :-
 I need to generate 1000 Random Numbers with in a range (0.5 < OUTPUT < INPUT) in such a way that total of this number is 1500.0
Now when this 1000 random numbers gets generated , 



AS A RESULT :-
For Result i will have to use following formula : RESULT = (INPUT/OUTPUT) * 100
And Result must be in between  (70 <  Result < 80) .


for Example ... RESULT = (INPUT/OUTPUT) * 100


SrNoInputOutPutResult
11.500.9070.70
21.101.4575.74
--------
10002.001.5876.52
Please note: this table Entry is dummy just for your understanding

CRITERIA :-> In above table TOTAL OF INPUT MUST BE 2000 AND TOTAL OF OUTPUT MUST BE 1500.
-> INPUT MUST BE GREATER THEN OUTPUT AND BOTH INPUT AND OUTPUT MUST BE NON ZERO
-> RESULT MUST BE BETWEEN 70 TO 80
-> TOTAL ENTRY MUST 1000 ONLY
-> AFTER POINT TWO VALUES ARE ALLOWED i.e(1.25432 = 1.25) 
 


So in short i need to generate a random numbers based on this logic and then needs to insert into table so that i can display it using grid .so please let me know sql query for this.





 


Answers (1)