diff --git a/libraries/Desktop/support/sitl_adc.h b/libraries/Desktop/support/sitl_adc.h
index 6a21d6f0f95a2a61cd38cb53747c4366cec7eb37..348d433ff939b2b37afc855c5db55e89026b741a 100644
--- a/libraries/Desktop/support/sitl_adc.h
+++ b/libraries/Desktop/support/sitl_adc.h
@@ -8,6 +8,7 @@
 
 #include <stdlib.h>
 #include <math.h>
+#include "util.h"
 
 static const float vibration_level = 0.2;
 static const float drift_speed = 0.2; // degrees/second/minute
@@ -18,13 +19,6 @@ static const float noise_offset[8]= {     0,     0,     0,    0,   0,    0,    0
 static const float drift_rate[8]  = {     1.0, 1.0,   1.0,    0,   0,    0,    0,    0 };
 static const float base_noise = 2;
 
-// generate a random float between -1 and 1
-static double rand_float(void)
-{
-	float ret = ((unsigned)random()) % 2000000;
-	return (ret - 1.0e6) / 1.0e6;
-}
-
 static inline float gyro_drift(uint8_t chan)
 {
 	if (drift_rate[chan] * drift_speed == 0.0) {
diff --git a/libraries/Desktop/support/sitl_compass.cpp b/libraries/Desktop/support/sitl_compass.cpp
index 8d1d319a3734ed797831efd27ab3548ed80476d4..39912e895960eeeafd50024c31bea1e4f2350afe 100644
--- a/libraries/Desktop/support/sitl_compass.cpp
+++ b/libraries/Desktop/support/sitl_compass.cpp
@@ -30,6 +30,8 @@
 // using an APM1 with 5883L compass
 #define MAG_FIELD_STRENGTH 818
 
+#define MAG_NOISE 5
+
 /*
   given a magnetic heading, and roll, pitch, yaw values,
   calculate consistent magnetometer components
@@ -53,7 +55,7 @@ static Vector3f heading_to_mag(float roll, float pitch, float yaw)
 	// convert the earth frame magnetic vector to body frame, and
 	// apply the offsets
 	m = R.transposed() * Bearth - Vector3f(MAG_OFS_X, MAG_OFS_Y, MAG_OFS_Z);
-	return m;
+	return m + (rand_vec3f() * MAG_NOISE);
 }
 
 
diff --git a/libraries/Desktop/support/util.cpp b/libraries/Desktop/support/util.cpp
index 7656d36bf185812dfc21ba3fed99d14ffaea5c37..6a956533e36d160571d40e4a990d831d164eeb9e 100644
--- a/libraries/Desktop/support/util.cpp
+++ b/libraries/Desktop/support/util.cpp
@@ -13,6 +13,7 @@
 #include <math.h>
 #include <stdint.h>
 #include <fcntl.h>
+#include <AP_Math.h>
 #include "desktop.h"
 #include "util.h"
 
@@ -58,3 +59,15 @@ void convert_body_frame(double rollDeg, double pitchDeg,
 	*q = cos(phi)*thetaDot + sin(phi)*psiDot*cos(theta);
 	*r = cos(phi)*psiDot*cos(theta) - sin(phi)*thetaDot;
 }
+
+// generate a random Vector3f of size 1
+Vector3f rand_vec3f(void)
+{
+	Vector3f v = Vector3f(rand_float(),
+			      rand_float(),
+			      rand_float());
+	if (v.length() != 0.0) {
+		v.normalize();
+	}
+	return v;
+}
diff --git a/libraries/Desktop/support/util.h b/libraries/Desktop/support/util.h
index 7d55f827c65e016aa68b5bfa12563a17c56a3aba..7778adda1487a63d7e71e4ab8269498d2464230e 100644
--- a/libraries/Desktop/support/util.h
+++ b/libraries/Desktop/support/util.h
@@ -12,3 +12,10 @@ void runInterrupt(uint8_t inum);
 void convert_body_frame(double rollDeg, double pitchDeg,
 			double rollRate, double pitchRate, double yawRate,
 			double *p, double *q, double *r);
+
+// generate a random float between -1 and 1
+#define rand_float() (((((unsigned)random()) % 2000000) - 1.0e6) / 1.0e6)
+
+#ifdef VECTOR3_H
+Vector3f rand_vec3f(void);
+#endif