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.

40,026 questions

51,982 answers

573 users

How to generate random number in Swift

4 Answers

0 votes
import Foundation

var number: Int = 0;
var i: Int = 0;
		
while (i < 5) {
    number = Int(random()) 
	print(number);
	i += 1;
}	

	
	
/*
run:


1804289383
846930886
1681692777
1714636915
1957747793

*/

 



answered Oct 14, 2021 by avibootz
0 votes
var number: Int = 0;
var i: Int = 0;
		
while (i < 10) {
    number = Int.random(in: 1..<6)
	print(number);
	i += 1;
}	

	
	
/*
run:


2
5
1
4
4
1
3
2
4
3

*/

 



answered Oct 14, 2021 by avibootz
0 votes
var number: Int = 0;
var i: Int = 0;
		
while (i < 10) {
    number = Int.random(in: 1...6)
	print(number);
	i += 1;
}	

	
	
/*
run:


2
4
3
1
2
3
2
1
1
6

*/

 



answered Oct 14, 2021 by avibootz
0 votes
var number: Float = 0.0;
var i: Int = 0;
		
while (i < 10) {
    number = Float.random(in: 0..<1)
	print(number);
	i += 1;
}	


	
	
/*
run:

0.8994361
0.14668012
0.86947435
0.52765006
0.5495861
0.2248978
0.6484431
0.51564634
0.10083586
0.78760487

*/

 



answered Oct 14, 2021 by avibootz

Related questions

...