Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Turing Random Numbers
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
anshu402




PostPosted: Sat Feb 16, 2013 11:37 am   Post subject: Turing Random Numbers

i need to create a program where the program generates 6 random numbers between 1-49. however, the numbers cant repeat themsleves. How do i do that? My code:
var ran: array 1..6 of int

for i: 1..6
randint (ran(i),1,49)
put ran(i)

end for
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: Sat Feb 16, 2013 12:29 pm   Post subject: RE:Turing Random Numbers

There are two ways you do this.

1) Keep rolling your dice until you get a number you haven't used before. You then add that number to the list in your head.

With this method, it's improbably possible to keep rolling numbers you've already rolled for a long time. Each time you do this process, it would take a variant amount of time.

2) Everyone puts their name on a piece of paper and put it in a hat (list). Shuffle them around and pull out the names.

With this, you can limit the shuffling to a finite amount of time (swaps).
hamid1455




PostPosted: Sun Feb 17, 2013 1:03 pm   Post subject: RE:Turing Random Numbers

I would say to save the number generated into a variable and then use an if statement to check if the new random number is the same as the one saved in the variable.
Raknarg




PostPosted: Sun Feb 17, 2013 2:49 pm   Post subject: RE:Turing Random Numbers

have an array of 1 - 49, make a for loops to go through the program 49 times, each iteration you switch ran(i) with ran (rand.Int (1, 49) then pick the first six numbers.

Simplest solution I can think of.
evildaddy911




PostPosted: Sun Feb 17, 2013 2:56 pm   Post subject: Re: Turing Random Numbers

The algorithm I use for this sort of thing
Tony




PostPosted: Mon Feb 18, 2013 1:20 pm   Post subject: Re: Turing Random Numbers

evildaddy911 @ Sun Feb 17, 2013 2:56 pm wrote:


This.

It should be quite natural for most people to figure out how to draw 6 random cards from a deck. Write a number on the card, and you get a list of numbers from a set.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: