uint8_t pwm_value = 0;
float signal = 0;
Serial.println(“polarization scrambler 0.1”);
randomSeed(analogRead(A0)); // to have a bit of a random start
int x = random(2)
digitalWrite(4, x); // your square wave
signal = signal + 0.0001;
if (signal > 2*PI) signal = 0;
int pwm_value = 127 + 127 * sin(signal); // make a sinusoidal pwm value
if (x == 0) pwm_value = 127; // the random square wave works as a gating for the sinus signal making is 0 at random times and sinusoidal the other times.
I think I did the other way around, I made the sinus signal random. If this is not what you want can you post a drawing of how the PWM signal should look like (OK randomized will always be different) or as grumpy says, we need proper requirements.
http://en.wikipedia.org/wiki/Pulse_density_modulation more like the graph on this page. yet its random sine wave based on random 1 or 0