Unexpected patterns in Verilog $random
I have written a little testbench that demonstrates the problem stand-alone:

module testbench;

integer i, j = 0;
reg [31:0] randval;

initial begin
    for (i = 0; i &lt; 100000; i = i+1) begin
        randval = $random;
        if (randval[0 +: 6] == 0) begin
            $display("%8d %6d: %x -&gt; %d %d", i, j, randval, randval[0 +: 6], randval[24 +: 4]);
            if (randval[24 +: 4] != 0) $finish;
            j = j + 1;
        end
    end
    $display("IEEE Std 1364-2005 $random (rtl_dist_uniform(seed, LONG_MIN, LONG_MAX)) sucks!");
end

endmodule


The really interesting thing here is that the exact behavior of $random is defined in IEEE Std 1364-2005. There is actually C code in the standard (pages 317 and 318). I don't want to quote it here in full, but a copy of the code can be found for example in Icarus Verilog:

https://github.com/steveicarus/iverilog/blob/master/vpi/sys_random.c

Calling $random in Verilog equals to calling rtl_dist_uniform(&amp;a_seed, INT_MIN, INT_MAX) in this C file.

So what you demonstrated here is not only a weakness in $random of just one particular simulator, but a weakness in $random in general.

One solution would be to simply implement your own random number generator. I often use the Xorshift family of random number generators because they work fairly well and are easy to implement:

http://en.wikipedia.org/wiki/Xorshift

The following example uses a 64 bit xorshift to generate 32 bit numbers:

module testbench;

reg [63:0] xorshift64_state = 64'd88172645463325252;

task xorshift64_next;
    begin
        // see page 4 of Marsaglia, George (July 2003). "Xorshift RNGs". Journal of Statistical Software 8 (14).
        xorshift64_state = xorshift64_state ^ (xorshift64_state &lt;&lt; 13);
        xorshift64_state = xorshift64_state ^ (xorshift64_state &gt;&gt;  7);
        xorshift64_state = xorshift64_state ^ (xorshift64_state &lt;&lt; 17);
    end
endtask

integer i;
initial begin
    for (i = 0; i &lt; 100; i = i+1) begin
        xorshift64_next;
        $display("%x", xorshift64_state[31:0]);
    end
end

endmodule