![]() |
[QUOTE=3.14159;268354]That's a nice step.. But I'd need it to also continuously redefine the variable for me.
What I'm trying to do is something similar to this: [code]for(n=1,20, print(random(10))) 4 7 8 0 0 6 5 4 3 5 4 7 6 1 3 0 9 4 5 7[/code] It printed random numbers from 0-9 (Why the hell not 1-10?? for random([b]10[/b])) I'd like to do the above, but excluding those numbers less than or equal to 5. If it's impossible in PARI/GP, feel free to point me to where it is possible to do so. Though I'd be very disappointed if it were actually impossible to do.[/QUOTE] if you allow an upper limit I'd try something like: [code]for(n=1,20,until(a>5,a=random(10));print(a","))[/CODE] [QUOTE]random({N=2^31}): random integer between 0 and N-1.[/QUOTE] that's why |
Thanks for the advice on the random function.
Okay, that's closer, but not quite yet it. What I would like to do is this: random(a)+b - (random(c)+d) Print 20 results, however, all results that are < 0 get the message, "no number here" instead. |
[QUOTE=3.14159;268373]Thanks for the advice on the random function.
Okay, that's closer, but not quite yet it. What I would like to do is this: random(a)+b - (random(c)+d) Print 20 results, however, all results that are < 0 get the message, "no number here" instead.[/QUOTE] so: [CODE]e=0;until(e>20,for(b=1,100,for(d=1,100,a=random();c=random();if((a+b)-(c+d)>0,print1((a+b)-(c+d)",");e=e+1;if(e>20,break(3))))))[/CODE] except more cleaned up ? |
Kind of like this:
[code](21:17) gp > for(n=1,20, print(random(40)+6 - (random(30)+11))) 15 -30 -27 9 7 0 21 2 -12 7 -3 19 -3 18 -34 0 5 -22 8 -22[/code] But all negative numbers/zeros get replaced by "no number here" |
[QUOTE=3.14159;268377]Kind of like this:
[code](21:17) gp > for(n=1,20, print(random(40)+6 - (random(30)+11))) 15 -30 -27 9 7 0 21 2 -12 7 -3 19 -3 18 -34 0 5 -22 8 -22[/code] But all negative numbers/zeros get replaced by "no number here"[/QUOTE] altering yours I got : [CODE]for(n=1,20,a=random(40);b=random(30);print(if(a+6 - (b+11)>0,a+6 - (b+11),"no number here")))[/CODE] |
Yes! I'll do some more testing
This looks exactly on target Thanks a million! :smile: |
[QUOTE=3.14159;268379]Yes! I'll do some more testing
This looks exactly on target Thanks a million! :smile:[/QUOTE] remember you can do a if within a print to choose what to print. |
Okay, thanks for the tip.
Also, I didn't understand how [code]for(n=1,20,a=random(40);b=random(30);print(if(a+6 - (b+11)>0,a+6 - (b+11),"no number here")))[/code] worked. |
It stores a and b, which are random numbers on [0, 39] and [0, 29] respectively. If a+6 - (b+11)>0, that is, a > b+5, it prints the difference a+6 - (b+11). Otherwise, it prints "no number here". This process is repeated a total of 20 times.
I would write this [code]{for(n=1,20, t=random(40)-random(30)-5; print(if(t > 0, t, "no number here")) )}[/code] |
Anywho, in the spirit of somewhat old times..
Primality testing 17025*2^18800+1 [N-1, Brillhart-Lehmer-Selfridge] Running N-1 test using base 7 Special modular reduction using all-complex FFT length 1536 on 17025*2^18800+1 Calling Brillhart-Lehmer-Selfridge with factored part 99.93% 17025*2^18800+1 is prime! (0.4559s+0.0015s) |
[QUOTE=science_man_88;268380]remember you can do a if within a print to choose what to print.[/QUOTE]
.. Sm88 .. Primecare .. See light .. Shut up & drive .. Lol |
| All times are UTC. The time now is 22:54. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.