Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2012/5.0 > C# 2012/5.0 General Discussion
C# 2012/5.0 General Discussion Discussions about the C# 2012 language and tool not related to any specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2012/5.0 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 25th, 2014, 01:52 PM
Authorized User
Join Date: Nov 2012
Posts: 25
Thanks: 3
Thanked 0 Times in 0 Posts
Default I need to know how to generate random number without any repeating numbers.

I need to now how to generate a set of random numbers without any repeating numbers being generated. for example, if I were to generate a number from 1 to 10, I would get numbers 1,2,3,4,5,6,7,8,9,10 in any order without any number being generated twice.

Please help me create the code for my problem.

Old March 14th, 2014, 12:37 AM
Friend of Wrox
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts

var numbers = new List<int>();

While( numbers.Count < 100 )
      var number = (int) rand.Next();
      if( !numbers.Contains( number ) )
I'll leave you to set up the random number generator
Old May 24th, 2014, 01:44 AM
Posts: n/a

Random numbers can be quickly and easily generated by using the graphing calculator.
Let's start our investigation by looking at generating random integers.
(The TI-84+ is being used on this page.)

Generating Random Integers on the Home Screen: (good for games)

Go to MATH → PRB
Choose #5 randInt(

From the home screen, enter the smallest value needed, followed by the largest value. Hitting ENTER will generate the random integers.
(Random values may repeat.)
This example generates random numbers from 1 to 25 (good for Bingo).

Adding a third parameter
indicates the number of
random integers that will
appear on the screen at
one time.

Generating Random Integers in Lists: (good for statistical studies)

Go to MATH → PRB
Choose #5 randInt(

From the home screen, enter the randInt followed by the smallest value in the desired range, the largest value, and the number of terms needed. The results are stored (STO) into List 1.
This example stores 100 random integers from 0 to 1 in L1 to
simulate the toss of a coin.

OR, from the list screen, arrow up onto L2, and type
randInt(0,1,100). Hit ENTER.
Be sure to enter the third parameter
so the calculator will know "how
many" numbers to place in the list.

Such lists can be used to simulate the toss of one (or more) fair coin(s). The number of entries represents the number of tosses. An even random number represents heads, while an odd number represents tails.

If tossing one coin, use sum command to count the number of heads,
where heads are 1, and tails are 0.
2nd STAT - MATH - #5 sum

Using the rand command: (not integers)
The rand (MATH → PRB #1 rand) command will generate random values, not integers.

MATH → PRB #1 rand

The rand command will create a random number between 0 and 1.

To generate a random number between 0 and 15, enter

This last entry shows how to generate a list of 10 random numbers between 0 and 15 and store them in List 1.

Re-Seeding the Random Number Generator:
Calculators (and computers) are not capable of creating "truly random" numbers. They create what are called "pseudo-random" numbers, meaning they use a formula to create the values. To engage this formula, the calculator uses a starting value, called a "seed", and then creates the random numbers based upon this seed. If two calculators start with the same seed value, they will generate the same sequence of random values.

If you wish, you can control the starting "seed" value.
To seed the random generator,
choose a seed value and store
it into the rand command.

Now, start generating your random values.
If you feed two calculators the same seed value, they will each produce the same result when rand is entered.

After running a RESET (DEFAULTS) the calculator
will return to using its default
seed value. Engaging rand
will always produce the value
seen above. This same value
will appear on all TI-84+
calculators after a reset.

If you wish to ensure that each student in the class has a different set of random numbers, assign a different number to each student as their seed value. You could also have the students enter their birth date as the random seed (04021990), assuming no two students have the same birth date.

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i generate random numbers with mysql for students 2 register on a school site www.freegist.com Beginning PHP 0 April 16th, 2012 06:02 AM
how to generate random numbers in xslt anboss XSLT 3 July 23rd, 2008 09:10 AM
generate Random number in MS SQL server 2000 nax111 SQL Server 2000 9 March 29th, 2007 10:14 PM
how to generate random non repeated numbers in php method PHP How-To 0 February 6th, 2006 02:36 PM
Random Numbers not so random... katsarosj ASP.NET 1.0 and 1.1 Basics 5 November 20th, 2003 12:55 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.