Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,999 questions

51,944 answers

573 users

How to generate 4 digits random numbers in PHP

2 Answers

0 votes
for ($i = 0; $i < 20; $i++) {
    echo rand(1000, 9999) . "\n"; 
}


/*
run

4576
5043
1859
1443
3675
7500
7407
9026
1487
4833
8125
8968
3955
6356
6109
9463
8619
9273
1256
2262

*/

 



answered Jul 6, 2020 by avibootz
0 votes
$digits = 4;

for ($i = 0; $i < 20; $i++) {
    $n = rand(pow(10, $digits - 1), pow(10, $digits) - 1);
    echo $n . "\n";
}



 
 
/*
run:
 
4443
1014
2889
8004
3594
8242
3863
9531
7291
1745
2670
4766
9344
2979
7648
7426
2443
8289
1808
8624

*/

 



answered Sep 30, 2021 by avibootz

Related questions

1 answer 94 views
1 answer 115 views
1 answer 111 views
1 answer 97 views
1 answer 132 views
1 answer 143 views
1 answer 165 views
...