solution…
to find prime numbers…
class prime_numbers;
parameter RANGE=1000;// this will give all prime number with in 1000, we can give any range here.......!!!
rand int unsigned prime[$];
constraint const_prime {prime.size inside {RANGE};
foreach(prime[i])
if (i>1 && (!((i%2==0 && i!=2) || (i%3==0 && i!=3) || (i%4==0 && i!=4) || (i%5==0 && i!=5) || (i%6==0 && i!=6) || (i%7==0 && i!=7) || (i%8==0 && i!=8) || (i%9==0 && i!=9))))
prime[i]==i;
else
prime[i]==2;
}
function void post_randomize;
prime = prime.unique();
endfunction
endclass
program top;
prime_numbers arr;
initial
begin
arr=new();
assert(arr.randomize());
$display("the prime: %p",arr.prime);
end
endprogram
output:::
# the prime: '{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 121, 127, 131, 137, 139, 143, 149, 151, 157, 163, 167, 169, 173, 179, 181, 187, 191, 193, 197, 199, 209, 211, 221, 223, 227, 229, 233, 239, 241, 247, 251, 253, 257, 263, 269, 271, 277, 281, 283, 289, 293, 299, 307, 311, 313, 317, 319, 323, 331, 337, 341, 347, 349, 353, 359, 361, 367, 373, 377, 379, 383, 389, 391, 397, 401, 403, 407, 409, 419, 421, 431, 433, 437, 439, 443, 449, 451, 457, 461, 463, 467, 473, 479, 481, 487, 491, 493, 499, 503, 509, 517, 521, 523, 527, 529, 533, 541, 547, 551, 557, 559, 563, 569, 571, 577, 583, 587, 589, 593, 599, 601, 607, 611, 613, 617, 619, 629, 631, 641, 643, 647, 649, 653, 659, 661, 667, 671, 673, 677, 683, 689, 691, 697, 701, 703, 709, 713, 719, 727, 731, 733, 737, 739, 743, 751, 757, 761, 767, 769, 773, 779, 781, 787, 793, 797, 799, 803, 809, 811, 817, 821, 823, 827, 829, 839, 841, 851, 853, 857, 859, 863, 869, 871, 877, 881, 883, 887, 893, 899, 901, 907, 911, 913, 919, 923, 929, 937, 941, 943, 947, 949, 953, 961, 967, 971, 977, 979, 983, 989, 991, 997}
tq daveeeee