randomSeed w/ random producing exact same numbers every time

Hi all! I'm new to this forum, and sort of new to Arduino (played with it on and off a couple years back). I mainly do tons of analog electronics, which I have a good hold of.

Anyway, introductions aside; I have been playing with a circuit to replace a sample and hold circuit with a noise source and have a basic setup working which basically uses an array of 12 values to be sent to a R-2R DAC (4 bit right now). So, I'm trying to generate a a random array using the 16 possible steps using this:

int s0 = random(15);
int s1 = random(15);
int s2 = random(15);
int s3 = random(15);
int s4 = random(15);
int s5 = random(15);
int s6 = random(15);
int s7 = random(15);
int s8 = random(15);
int s9 = random(15);
int s10 = random(15);
int s11 = random(15);
int segment[] = {B00000000,B00000001,B00000010,B00000011,B00000100,B00000101,B00000110,B00000111,B00001000,B00001001,B00001110,B00001111,B00001110,B00001111,B00001110,B00000001};
int d2OutC[] = {segment[s0],segment[s1],segment[s2],segment[s3],segment[s4],segment[s5],segment[s6],segment[s7],segment[s8],segment[s9],segment[s10],segment[s11]};

void setup() {
randomSeed(analogRead(4));
}

And no matter what I get these values for d2OutC (the array of s0 thru s15): 7 4 8 8 1 0 2 9 8 8 4 0 5

I tried ditching the analogRead(4) and just typing random values into randomSeed and I always get the same thing 7488102988405.

Am I missing something here? Or is this the universe telling me about some magical sequence? :slight_smile:

Many thanks for any help, ya'll!!

use the random seed 1.st . then the random function.

If U work with bytes.. use 'byte' instead of 'int'

knut_ny:
use the random seed 1.st . then the random function.

If U work with bytes.. use 'byte' instead of 'int'

But, doesn't the randomSeed have to be in setup, and doesn't setup() get executed first anyway? I'm pretty sure the compiler complained when I moved it out of there. Will look at that again.

devinw1:
But, doesn't the randomSeed have to be in setup...?

No.

OK, it's working now. It was the order of things indeed. Thanks guys.

Getting the hang of this slowly.