randomSeed? need larger variation.

Hello,

I recently read about the "joke-a-tron". An electronic prank device that beeps around every 10 min. or so that you hide in an office, car, house, ect. The only draw back to the prank that i saw was the consistent timing which in my eyes makes it easy to track down.

I had the idea to use the Arduino's randomSeed to randomly select a time between 15 and 120 min. so tracking would be a bit more of a challenge. I set the min / max to 900,000 / 7,200,000.

The problem is that randomSeed(0) as well as randomSeed(analogeRead(0)) only seem to variate an avarage of 20,000 or 5 1/2 min.. I let it run all day and it ranged from 900,150 to 932,614.

Is there a way i can get the variable to swing through the entire range and not come up with such small variations from calculation to calculation?
Additionally is there an easy way to boost the output from 5v to more like 9v or 12v. Louder is better lol.

Thanks.
Please see the code listed below for reference.

long delayval = 0;
int buzzer = 9;
int led = 13;

void setup(){
  Serial.begin(9600);
  randomSeed(analogRead(0)); 
  pinMode(led, OUTPUT);
  pinMode(buzzer, OUTPUT);
}

void loop() {
  digitalWrite(led, HIGH);
  digitalWrite(buzzer, HIGH);
  delay(1000); 
  digitalWrite(led, LOW);
  digitalWrite(buzzer, LOW);
  delayval = random(900000,7200000);  
  Serial.print("delayval: ");
  Serial.println(delayval);
  delay(delayval);
}

Thanks again.

you could just multiply two randoms? and constrain them?

and you could have used some sort of conditions to chech if it is variated enough, say at least 500000 each time?

Looks like rand() returns a RAND_MAX of 32,767, so random(min, max) will only give you a number between min and (min + 32,767).

You probably don't care about millisecond resolution, so why not:

delay(random(900,7200)*1000) ;

you could just multiply two randoms? and constrain them?

and you could have used some sort of conditions to chech if it is variated enough, say at least 500000 each time?

The concept of fudging pseduorandom numbers to make them look more random bothers my mathematician's brain.

The concept of fudging pseduorandom numbers to make them look more random bothers my mathematician's brain.

They're just making a larger random out of two smaller ones, not really trying to make it "more random".

Besides, it shouldn't be any worse than the whole concept of pseudorandom numbers itself. :slight_smile:

-j

The concept of fudging pseduorandom numbers to make them look more random bothers my mathematician's brain.

They're just making a larger random out of two smaller ones, not really trying to make it "more random".

Besides, it shouldn't be any worse than the whole concept of pseudorandom numbers itself. :slight_smile:

-j

It's the part about making sure the variation is high enough that bugs me. Most people can't intuitively pick out a random sequence from a human generated "random" sequence. The true random one doesn't look random enough.

Thanks all for the input. I think i will try something like what jmknapp suggested.

For clarification it's not so much i insist on a large variation at each recycle of the loop as it is i want the total variation not to be within such a small portion of the total min/max. Out of a span of 105 min. it was always generating a number within a 5.5 min. of one section of the total span. If i were to try to control the randomness of the random number the number would just get less random.......Wait what? :wink:

Thanks again to all who replied.

I didn't mean to say you were looking to fudge numbers or jmknapp's very effective solution would have that effect.

I was just referring to the comment I quoted.

Good luck with your project, and the answer jmknapp gave you will do exactly what you want, scale the random number to the range you need.