Message Boards Message Boards

3
|
7183 Views
|
4 Replies
|
9 Total Likes
View groups...
Share
Share this post:
GROUPS:

Maybe a bug in RandomPrime function.

Posted 9 years ago
lis=Table[RandomPrime[{10^i,10^(i+1)},{2,2}],{i,6}]

I think every element in lis should be a 2*2 list, but I get this answer:

enter image description here

is it a bug?

POSTED BY: Yuqiang Zheng
4 Replies

Ok, that does not look right. I can reproduce the problem on OS X, MMA 10.0.2, too.

This command is a workaround:

RandomChoice[Select[Range[100000, 500000], PrimeQ], {2, 2}]

but it is about 100 times slower.

This one is as fast as the original:

Prime@RandomChoice[Range[PrimePi[100000], PrimePi[500000]], {2, 2}]

Cheers, Marco

POSTED BY: Marco Thiel

Thanks for bringing this issue up. The behavior certainly appears inconsistent. I sent a report to our development team. It appears Marco Thiel provided a good work-around for this.

POSTED BY: Jason Grigsby

Watch this:

     RandomPrime[{100000, 499999}, {2, 2}]
         (* {{246251, 287611}, {415111, 277003}} *)

and now

     RandomPrime[{100000, 500000}, {2, 2}]
              (* {{457889, 394619}} *)

And additional observation: There are 2 prime numbers between 499,970 and 499990

     PrimePi[499999] - PrimePi[499970]
     (* 2 *)

So RandomPrime[{499970, 499999}, {2, 2}] returns these 2 numbers twice {{499979, 499973}, {499973, 499973}} since we asked for 2 by 2 output. But RandomPrime[{499970, 500000}, {2, 2}] returns these 2 numbers one time {{499973, 499979}}. Very strange why it does this when the top range goes over 499999.

So, I would say it looks like a bug.
Version 10.02, on windows 7, 64 bit

POSTED BY: Nasser M. Abbasi

Simpler workaround:

Table[RandomPrime[{100000, 500000}], {2}, {2}]
POSTED BY: Ilian Gachevski
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract