0
$\begingroup$

I wanna evaluate how large prime numbers my computer work at most 60 seconds. Of course, I can evalutate this manaully e.g. by trying different values. However, can I do this differently, e.g. by setting the time?

$\endgroup$
6
  • $\begingroup$ Hi! Please, take the time to read your question and provide us with a minimum reproducible example. As it is currently written you are generating a random prime in the range {10^2000, 10^2000}. Also - what is your end goal? Generating prime numbers? Filtering them afterwards? $\endgroup$
    – Sektor
    Commented Mar 6, 2021 at 18:17
  • $\begingroup$ Hi, sorry it should be '''{10^1999, 10^2000}'''. $\endgroup$
    – user77670
    Commented Mar 6, 2021 at 18:19
  • $\begingroup$ My end goal is that I wanna have the maximum digit prime I could generate in 60 seconds. As of right now, I can only get the time for a given prime. I wanna have a function that works in the opposite way. $\endgroup$
    – user77670
    Commented Mar 6, 2021 at 18:21
  • $\begingroup$ So I wanna set the time manually, e.g.60 second or 80 seconds and then generate maximum digit prime based on this time. $\endgroup$
    – user77670
    Commented Mar 6, 2021 at 18:22
  • $\begingroup$ It produces {9.45313, \ 6874090616771610210074487399211060171147764570196238070783173836677958\ 1619995425908424621945207150352924177002190160746774878511809371120288\ 910835110915978986241...} on my comp. $\endgroup$
    – user64494
    Commented Mar 6, 2021 at 19:04

1 Answer 1

3
$\begingroup$

This should do what you want. You can change the argument of PrimeQ based on the granularity you are looking for VS the time you want to spend. TimeConstrainted aborts if the computation takes more than 60 seconds, CheckAbort returns Print[n] if PrimeQ took more than 60 seconds.

n = 10;
While[Not@CheckAbort[TimeConstrained[PrimeQ[10^(100*n) + 1], 60]
  , Print[n]], n++]

Returns n=176 for 10 seconds and n=304 for 60 seconds on my laptop.

You can check: PrimeQ[10^(100*304) + 1] // AbsoluteTiming returns 68 seconds (and False). If you are looking specifically for primes, you can adapt the above code.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.