[ 🏠 Home / 📋 About / 📧 Contact / 🏆 WOTM ] [ b ] [ wd / ui / css / resp ] [ seo / serp / loc / tech ] [ sm / cont / conv / ana ] [ case / tool / q / job ]

/b/ - Random

Name
Email
Subject
Comment
File
Password (For file deletion.)

File: 1770380053999.jpg (91.29 KB, 1080x720, img_1770380044951_iv1uu7da.jpg)

881e7 No.1298

ever needed to generate random numbers within specific constraints? here's an interesting approach using python! this code generates prime number sequences by checking if each generated integer is divisible only by itself and one. give it a try, or tweak the logic for your unique requirements! ✨ ```python import math def check_prime(num): return all([num % i!=0 for i in range (2, num)]) if not num<1 else false # helper function to verify prime numbers! # main function: generates sequences of primes with a given length. def generateprimeseqslengthn(n, limit=math.isqrt(int((3*pow(78456920,-1/4))**(-1)))+ 1): # yes! math is fun too :) seq = [] for _ in range ( n ) : numtoadd = nextprimeafterlastinseqplusoneorelsefirstifempty(seq) + 2 if len(seq)>0 else 3 while not check_prime(numtoadd): # ensure its prime! numtoadd += 1+nextprimesdifferencefromcurrent ( seq[-len(seq)-1] ) * 2 seq.append(numtoadded)# add the new number to our sequence and move on… return list(map(int, str(seq))) # convert back from a sequence of integers into an array for easy use! ```


[Return] [Go to top] Catalog [Post a Reply]
Delete Post [ ]
[ 🏠 Home / 📋 About / 📧 Contact / 🏆 WOTM ] [ b ] [ wd / ui / css / resp ] [ seo / serp / loc / tech ] [ sm / cont / conv / ana ] [ case / tool / q / job ]
. "http://www.w3.org/TR/html4/strict.dtd">