How do I generate random numbers to fill in empty rows?

Matt

I've added two new columns on one of my database's table. They are called Exam and assignment results.

This is the table

At the moment the two columns are both empty. I want them filled with random examination results but no greater than 100. How to I generate random number for both columns from 0 to 100?

Thanks.

Gordon Linoff

You can do this using rand(),checksum(), andnewid()`:

update t
    set exam = rand(checksum(newid())) * 101,
        assignment = rand(checksum(newid())) * 101;

In SQL Server, rand() is (essentially) called once for a query. To get around this, you can give it a new seed. You could also use other columns in each row as the seed value, if you wanted reproducible results.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I generate random numbers in Dart?

How do I fill NaN values with different random numbers on Python?

How do I generate random numbers x times?

How do I generate a vector of random numbers in a range?

How do I generate random numbers with a mean in C++?

How do I generate thread-safe uniform random numbers?

How do I generate random but unique numbers in python?

How do i generate a random numbers for each integer in an array?

How do I generate different random numbers in a loop in C?

How do I generate a random range of numbers within another range?

How do I generate a random list in Python with duplicates numbers

How do I generate a specific amount of random numbers?

How to generate random numbers for multiple rows in a column?

How do computers generate random numbers

How do I use random numbers to generate truly random results? ABS(CHECKSUM(NewID))) is not working

How do I fill an empty list in a for loop?

How do I generate non-repeating random numbers in a while loop? (Python 3)

How do I generate random numbers in an array that add up to a defined total?

How do i generate 2 random numbers, once within the range of 50 and 259, and once within 50 and 159?

How do I generate a multidimensional NumPy array with random numbers with the dimension of another array whose dimension is not declared?

How do I generate infinite random numbers of pair of dice until they are equal?

How do I generate random numbers but not repeating and within a certain range based on user input?

How do I fill an array with consecutive numbers

I want to generate random numbers then do the addition operation on them

How do I generate a random num::BigUint?

How do I generate a random int number?

How do I generate random doubles in an Array?

How do I generate a primary key that is not random?

How do I write code in order to generate random numbers in a way that a random number can only be printed once every 5 times