# shuffle

**URL:** <https://forum.xojo.com/t/shuffle/30143>\
**Category:** General\
**Created:** [March 5, 2016, 5:56am UTC](https://forum.xojo.com/t/shuffle/30143 "2016-03-05T05:56:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick\_Washabaugh](https://forum.xojo.com/letter_avatar_proxy/v4/letter/p/97f17d/32.png) [@Patrick\_Washabaugh](https://forum.xojo.com/u/Patrick_Washabaugh)\
**Post date:** [March 5, 2016, 5:56am UTC](https://forum.xojo.com/t/shuffle/30143/1 "2016-03-05T05:56:09Z")

</div>

Hello,  
I have a program that reads in a .txt datafile into a structure of  
record  
property name string  
property o variant  
property r variant

I can read the 105 row file nicely using an array like myArray(), by typing in a number and getting the results:Example type in 9, myArray(9).name

I have a sample program that uses the shuffle command and I read that into an array:  
aTest =Array(0,1,2,3,4,5)  
aTest.Shuffle

The program I’m using is able to shuffle the numbers and values without repeats, which I like.

Right now, I read the datafile and store the lines into: myArray with the unshuffled numbers.

I would like to know this:

Is it possible to read the datafile, shuffle or randomize the numbers of the array and then I want to use the newly shuffled numbers in my new array list.

If so, how would I do that?

Thanks for your help,  
Pat

---

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [March 5, 2016, 6:11am UTC](https://forum.xojo.com/t/shuffle/30143/2 "2016-03-05T06:11:19Z")

</div>

Shuffle works on arrays of any data type.  
After you read the data into myArray, just call

```auto
myArray.Shuffle
```

Then myArray(9).name will not be the one it was after you read from the file

---

<div class="post-metadata">

**Author:** ![Kem\_Tekinay](https://forum.xojo.com/user_avatar/forum.xojo.com/kem_tekinay/32/154_2.png) [@Kem\_Tekinay](https://forum.xojo.com/u/Kem_Tekinay)\
**Post date:** [March 5, 2016, 6:16am UTC](https://forum.xojo.com/t/shuffle/30143/3 "2016-03-05T06:16:16Z")

</div>

What Jeff said, although I’d change that to, “myArray(9) probably will not be the one it was” There is no telling after the shuffle.

Or are you looking for something like a “ShuffleWith” method where an array is shuffled but keeps one or more other arrays in sync? If so, create syncArray1, syncArray2, , then create indexArray() As Integer that holds the values 0 to syncArray1.Ubound. Then do something like this:

```auto
indexArray.Shuffle
indexArray.SortWith syncArray1, syncArray2, 
```

---

<div class="post-metadata">

**Author:** ![Patrick\_Washabaugh](https://forum.xojo.com/letter_avatar_proxy/v4/letter/p/97f17d/32.png) [@Patrick\_Washabaugh](https://forum.xojo.com/u/Patrick_Washabaugh)\
**Post date:** [March 5, 2016, 7:27pm UTC](https://forum.xojo.com/t/shuffle/30143/4 "2016-03-05T19:27:45Z")

</div>

Thanks for the help. I went to my program and went to the area right after I read the datafile into myArray. I put in the command: myArray.shuffle

This works great. every time I run the program now, it randomizes the numbers so it it never the same.

Thanks again,  
Pat

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:12pm UTC](https://forum.xojo.com/t/shuffle/30143/5 "2020-10-29T18:12:59Z")

</div>


