Random numbers are important in almost any programming paradigm. Here I will quickly go through creating a random number in some common programming languages.

Random in C/C++

Random in C#

Random in Kotlin


Random in Java

Similar to C#, to generate a random number, use Random class from util library.


Random in Python


Random in Swift

Swift 4.2+ makes it easier to generate a random number.


Random in Dart


Random in JavaScript/React.JS


Follow me

Tung Nguyen

PhD/Researcher/Programmer at Up Education - YooBee Colleges
I received the B.Eng. Degree in telecommunication from Shanghai University, MSc of the same major from Paris-Sud University and a PhD degree in Computer Science from Auckland University of Technology. My research interests include machine learning, game theory, computational trust, multi-agent systems and software engineering.
Follow me

Latest posts by Tung Nguyen (see all)

Login with your social ID or Credentials