473,321 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Shuffle a group of numbers

Hello Every one !

Suppose i have a vector a=[1 2 3 4 5 6 7 8 9 10]

Now i want to shuffle these number! and produce new vector b which consist of shuffle numbers which is best way to do it !

This problem is very similar to shuffle a group of cards!

I have a approach in my mind like

Take a random number from a, put it in a b in random position then choose another one from a put it randomly in b ! Question how to do it
May 31 '10 #1
2 2731
jkmyoung
2,057 Expert 2GB
That is a good approach. For the first run, you want to get a number between 0 and length of the vector - 1

So set index = (int)(rand() * length)
remove object at index from the first vector.
add this object to new vector.
repeat until the first vector is empty.
May 31 '10 #2
whodgson
542 512MB
You could also use random_shuffle(a,a+10) which resides in the <algorithm> header file.
Jun 3 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: alanbe | last post by:
Greetings I am making a flashcard type application to help me in my TCP/IP protocols test. My instructor will test us periodically on how a device or networking function relates to the OSI...
6
by: CaseyB | last post by:
If I wanted to create a game like Solitaire that would first randomly shuffle a deck of cards, I figured out that all I had to use is the Random() class or rnd and make sure I use the Randomize...
5
by: jacob.dba | last post by:
I have a table with first name, last name, SSN(social security number) and other columns. I want to assign group number according to this business logic. 1. Records with equal SSN and (similar...
28
by: Elfour | last post by:
In c++ what is the code to make teh program randomly select a number?
4
by: eltower | last post by:
Hey all, I'm trying to write a program in Python for learning purposes which is meant to: Generate a random number from 0 to 6 Insert this random number to the end of a list unless the number...
6
by: Happy YN | last post by:
in a Db there are 2 fields which contain 'matching' data. (there are other columns too) A Genesis B Exodus C leviticus D Numbers E Deutronomy I want to shuffle both columns so they are both...
10
by: Chris | last post by:
I am using an access database and have range of years for customers and want to group them together. for example: 1990 1991 1992 1993 1994 1998
1
by: ywangmda | last post by:
Hi everyone! I am a new user of Crystal Reports and have a question on Crystal Reports 10. I have a set of data with values such as 1.01 to 400.99, and would like to group them in every 1, that is,...
25
by: tooru honda | last post by:
Hi, I have read the source code of the built-in random module, random.py. After also reading Wiki article on Knuth Shuffle algorithm, I wonder if the shuffle method implemented in random.py...
16
by: wokeup2sleep | last post by:
im a beginner at comp science, and my prof is using python, which is totally new tom me i had a few questions with the program im writing, im having a few problems. brief summary i have to do a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.