Generate Random Integer Between Two Values in Scala

Generate Random Integer Between Two Values in Scala

Hi,

I am working on the SCALA project and want to generate random integer between two numbers.

How to Generate Random Integer Between Two Values in Scala?

Thanks

View Answers

November 13, 2017 at 12:38 PM

Hi,

Here is code example:

import scala.util.Random
val randomGenerator = new Random
val start = 20
val end = 70
val genValue = start + randomGenerator.nextInt( (end - start) + 1 )

The scala.util.Random class is used for generating random number.

If you run the code it will give following output:

scala> import scala.util.Random
import scala.util.Random

scala> val randomGenerator = new Random
randomGenerator: scala.util.Random = scala.util.Random@4b23c30a

scala> val start = 20
start: Int = 20

scala> val end = 70
end: Int = 70

scala> val genValue = start + randomGenerator.nextInt( (end - start) + 1 )
genValue: Int = 62

scala>

Thanks









Related Tutorials/Questions & Answers:
Generate Random Integer Between Two Values in Scala
Generate Random Integer Between Two Values in Scala  Hi, I am working on the SCALA project and want to generate random integer between two numbers. How to Generate Random Integer Between Two Values in Scala? Thanks   
Generate Random Integer Between Two Values in Scala
Generate Random Integer Between Two Values in Scala  Hi, I am working on the SCALA project and want to generate random integer between two numbers. How to Generate Random Integer Between Two Values in Scala? Thanks   
Advertisements
Generate random number between two numbers in Scala
Generate random number between two numbers in Scala  Hi, How to Generate random number between two numbers in Scala? Thanks   Hi, Following code can be used for generating random number in scala: val rand = new
Generate random number between two numbers in Scala
Generate random number between two numbers in Scala  Hi, How to Generate random number between two numbers in Scala? Thanks   Hi, Following code can be used for generating random number in scala: val rand = new
generate random integer matrix in r
generate random integer matrix in r  Hi, I want to generate random integer matrix in r. What is easy code to generate random integer matrix in r? Thanks   Hi, Following is the code for generating random integer
Default constructor generate two random equations
Default constructor generate two random equations  Need to create a default constructor in a programmer defined class that generates a random question, addition or subtraction. And when adding the numbers must be random from 0-12
How to store two integer value in a separate file and retrieve those values
How to store two integer value in a separate file and retrieve those values  I need to save two values so i can use those values later i came up with idea of saving those values in a separate file and updating values in file
Generate random numbers in Java
code can be used to generate a random number between 0,1000: int randomInt...Generate random numbers in Java - How to use the java.util.Random class to generate desired random number in Java program? In this tutorial I will teach you
How to generate a list of random numbers?
of Scala programming and it generates random integer. Following program...How to generate a list of random numbers?  Hi, How to generate a list of random numbers? I want code in scala programming language. Thanks  
How to generate a list of random numbers?
of Scala programming and it generates random integer. Following program...How to generate a list of random numbers?  Hi, How to generate a list of random numbers? I want code in scala programming language. Thanks  
How to generate a list of random numbers?
of Scala programming and it generates random integer. Following program...How to generate a list of random numbers?  Hi, How to generate a list of random numbers? I want code in scala programming language. Thanks  
How do I generate random number?
How do I generate random number?  In my Java program there is a requirement of generating random numbers between two given numbers. How do I write..., The java.util.Random class can be used to generate the random numbers. Check the tutorial
Generate Random Numbers
Generate Random Numbers  hi,,, Please give me answer with example How do you generate random numbers within a given limit with actionscript... This function generate random numbers with in given limit
swap two integer arrays
swap two integer arrays  int [] array1 = {1,2,3,4,5} int [] array2 = {6,7,8,9,10} how can we swap the values of bith integer arrays results like this array1 = {6,7,8,9,10} array2 = {1,2,3,4,5
swap two integer arrays
swap two integer arrays  int [] array1 = {1,2,3,4,5} int [] array2 = {6,7,8,9,10} how can we swap the values of bith integer arrays results like this array1 = {6,7,8,9,10} array2 = {1,2,3,4,5
swap two integer arrays
swap two integer arrays  int [] array1 = {1,2,3,4,5} int [] array2 = {6,7,8,9,10} how can we swap the values of bith integer arrays results like this array1 = {6,7,8,9,10} array2 = {1,2,3,4,5
How to generate random number in java
How to generate random number in java In this section you will learn how to generate random number in java. Java API  provide a random class in java.util.Random package which generate random number within a range. The random
Hibernate Built-in criterion "between" Integer
Hibernate Built-in criterion "between" Integer In this tutorial you will learn about how to use the built-in criterion ' between ' with the integer values. Hibernate provides the facility to make a Criteria query
Populating a list is Scala with random double
Populating a list is Scala with random double  Hi, I am writing Big Data Analytics program and there is need of populating random double values. Is there any easy for this? I want code for Populating a list is Scala with random
Populating a list is Scala with random double
Populating a list is Scala with random double  Hi, I am writing Big Data Analytics program and there is need of populating random double values. Is there any easy for this? I want code for Populating a list is Scala with random
generate random numbers and display the largest
generate random numbers and display the largest  Hi, I am using... creates an array and fills it with random ints, prints the contents... ArrayRandom{ public static void main(String args[]){ Random r = new Random
ModuleNotFoundError: No module named 'random_string_generate'
ModuleNotFoundError: No module named 'random_string_generate'  Hi...: No module named 'random_string_generate' How to remove the ModuleNotFoundError: No module named 'random_string_generate' error? Thanks   Hi
ModuleNotFoundError: No module named 'random_string_generate'
ModuleNotFoundError: No module named 'random_string_generate'  Hi...: No module named 'random_string_generate' How to remove the ModuleNotFoundError: No module named 'random_string_generate' error? Thanks   Hi
Generate random numbers from 1 to 100
Generate random numbers from 1 to 100  1)A class Called: RandomNumberGenerator that generate random numbers from 1 to 100 2)A class Test that tests... an object from the Random NumberGenerator class to generate your input test data
Generate array of random numbers without repetition
Generate array of random numbers without repetition In the previous section, you have learnt how to generate an array of random numbers from the given array... created an application that will generate the array of random numbers without
SQL BETWEEN Operator
of data between two values. In SQL, the BETWEEN operator is used to select a range of data between two values. These values can be number, text and dates. ... to return a records between two values. The Syntax used in SQL Like is given
how to generate random questions - Java Beginners
how to generate random questions  i am designing a test engine, i want my questions to be generated randomly. how can i do this?   Hi..."; Random generator = new Random(); int r = generator.nextInt(questionAr.length
calculate difference between two dates
calculate difference between two dates  hi, I was actually working on to calculate the number of days between two dates of dd/mm/yyyy format... the difference between the two dates
To get the String between two strings
To get the String between two strings  How to get string between two strings repeatedly using java?   Hi, Please tell me more about what do you want to achive.ADS_TO_REPLACE_1 Thanks
mysql difference between two numbers
mysql difference between two numbers  How to get total bate difference between two dates for example 1/01/2012 and 1/02/2012 in MYSQL?   ... between two date. The syntax of DATEDIFF is .. SELECT DATEDIFF('2012-01-31 23:59
Hibernate's Built-in criterion: Between (using Integer)
Hibernate's Built-in criterion: Between (using Integer... will learn to use "between" with the Integer class. "Between" when used with the Integer object, It takes three parameters e.g.  between("
calculate difference between two time in jsp
calculate difference between two time in jsp  How to calculate difference between two dates
java collision detection between two images
java collision detection between two images  java collision detection between two images
Collision Detection between two images in Java
Collision Detection between two images in Java  Collision Detection between two images in Java
how to get string between two characters
how to get string between two characters  hgow to get string from between two characters. ex:[email protected] from the above word i want a string between characters . and @ send the required method and give better example
Listing all even numbers between two numbers
Listing all even numbers between two numbers  Hi, How to write code to list all the even numbers between two given numbers? Thanks   Hi... the numbers. Check the tutorial Write a program to list all even numbers between two
How to manage cookie in between two JSP Pages
How to manage cookie in between two JSP Pages  How to manage cookie in between two JSP Pages   you can set cookies in response object e.g.response.addCookie(new Cookie("userName","Password")). Chandraprakash Sarathe
display dates between two dates - Java Beginners
display dates between two dates  hi can any one help me to writing this code, i need to store the dates between to dates so that i can retrive the data from the db using theses dates. its urgent pls tell me as possible
how to generate automatic bill based on selected values using jsp/javascript?
how to generate automatic bill based on selected values using jsp/javascript?  how to generate automatic bill based on selected values using jsp/javascript
days between two given dates using PHP
days between two given dates using PHP  How can we know the number of days between two given dates using PHP?   Hi friends, Example: <html> <head> <title>Number of days between two
list of all months between two dates in java
list of all months between two dates in java  Hi, I want to get list of all months with year between two dates. How to do this in Java? Thanks   Hi, This is the example code which can be used: package test.app
Hi .Difference between two Dates - Java Beginners
Hi .Difference between two Dates  Hi Friend.... Thanks for ur Very good response.. Can u plz guide me the following Program.... difference between two dates.. I need to display the number of days by Each Month
list of all months between two dates in java
list of all months between two dates in java  Hi, I want to get list of all months with year between two dates. How to do this in Java? Thanks   Hi, This is the example code which can be used: package test.app
JavaScript check if date is between two dates.
JavaScript check if date is between two dates.  Check if date is between two dates?   <html> <head> <title>Date before...;/head> <body> <h2>Check if date is between two dates</h2>
python merge two dictionaries add values
python merge two dictionaries add values  Hi, In Python I have two dictionaries with same keys. I want to merge the two dictionaries and add the values (int values) into the merged dictionary. For example student marks in three
how can i draw line between two panel contaning circle and line between their center?
how can i draw line between two panel contaning circle and line between their center?   how can i draw line between two panel contaning circle and line between their center
How to select Data Between Two dates in Java, MySQL
How to select Data Between Two dates in Java, MySQL  How to select Data Between Two dates in Java, MySQL? Thanks in advance.   http://www.v7n.com/forums/coding-forum/294668-how-select-data-between-two-dates-php
can i insert values into two tables by a query - JDBC
can i insert values into two tables by a query  hi all, can i insert values into two tables by a query Thanks Bala k
MySQL random
MySQL random       In MySQL we can get the random records by using the method RAND() of MySQL. There are two versions of RAND() function : first RAND() and second is RAND(X
How to find out the friend user between two columns in sql database
How to find out the friend user between two columns in sql database  Hi, Can any one please tell me ..how to find out the friend user between two columns in sql database? In other words i wanted to get the corresponding data from

Ads