Question: Suppose I have a table with a field Value: v1, v2, v3, v4

when combines 2 rows:
sum = v1\*v2 + v1\*v3 + ... + v3\*v4

when combines 3 rows:
sum = v1\*v2\*v3 + v1\*v2\*v3 + ... + v2\*v3\*v4

Basically get combination of all rows first, and then get sum of each combination's product. I have written a vba class for this task, but it's very clumsy, just calculate every combination one by one. I would like to know is there any easier way to do this job? SQL query or linear algebra, any way could simplified the process is welcomed. 
Thanks.

Answer: 
The direct answer to your question is "No, you cannot do what you are asking", and the second answer is "Yes, you are thinking about this all wrong".

The reason is that you are generating completely random noise. What you are asking for is coherent noise. They are two completely different animals and you cannot get coherent noise from random noise. Hence my answer.

To explain why, you must understand this simple statement which I am repeating from the [excellent libnoise documentation](http://libnoise.sourceforge.net/glossary/index.html#coherentnoise):

---

**Coherent noise**
==================

*A type of smooth pseudorandom noise.*

Coherent noise is generated by a coherent-noise function, which has three important properties:

* Passing in the same input value will always return the same output value.
* A small change in the input value will produce a small change in the output value.
* A large change in the input value will produce a random change in the output value.

---

Random noise does not have these properties, and therefore is completely unsuitable for what you are trying to achieve.

I would suggest studying [Ken Perlin's latest (improved) reference implementation](http://mrl.nyu.edu/~perlin/noise/) and his [SIGGRAPH 2002](http://mrl.nyu.edu/~perlin/paper445.pdf) notes.

If you cannot understand or implement this, then just use a library such as [libnoise](http://libnoise.sourceforge.net/), an excellent and well used LGPL library originally in C++ which has also been ported to many other languages.
Rather use cellular automatons. The algorithm that you find [here](http://www.roguebasin.com/index.php?title=Cellular_Automata_Method_for_Generating_Random_Cave-Like_Levels) creates similar patterns that you you would like to see:

```
. . . . . . . . . . . . . . .
. . . . . # # . . . . . # . .
. . . . # # # # . . . # # # .
. . . . . # # # # . . # # # .
. . . . . . # # # # # # # . .
. . . . . . # # # # # # # . .
. . . . # # # # # # # # # . .
. . . # # # # # # # # # # . .
. . # # # # # # . # . # # . .
. . # # # # # . . # . . . . .
. . . # # # # . . . # # # . .
. . . # # # # . . . # # # # .
. . # # # # . . . . . # # # .
. . # # # # . . . . . # # . .
. . . . . . . . . . . . . . .

```