+1

Sorting an Array

If I MAKE A RANDOM ARRAY OF INT’S, HOW CAN I MAKE SURE THAT ANY NUMBER IS PEAKED 1 TIME ONLY? IN OTHER WORDS, I WANT TO RANDOMLY PLACE NUMBERS FROM 1 TO 100 IN AN ARRAY, WITHOUT REPETITION.

10/21/2019 11:58:47 AM

Sharon Keren

7 Answers

New Answer

+2

var shuffled_numbers = Enumerable.Range(1,100).OrderBy(a => Guid.NewGuid()).ToList() Should work...I think

+2

Sharon Keren Why did you not tell us this was for sudoku?

+2

Thomas Williams I was just about to write that. People don't know what they want to do or don't tell clearly, it just waste time and nothing else. Sharon Keren The solution was suggested to you based on what you described initially. Please learn to describe the problem/issue clearly. It will save time for everyone. Please be careful in future.

+2

sorry, i am new, will try better next time

+1

Can you share your code here So I can tell by looking your code

+1

Instead of generating random numbers and keeping track of whether the number has been generated previously or not, the best solution is to create an array of 100 elements, fill it with numbers from 1 to 100 and shuffle the array. There should be a direct way to do it else you can try something like (pseudo code) for (int i =0; i < 100; i++) { int j = rand() % (i+1); swap (arr[i], arr[j]); }

0

shuffle wont work, i think. i want to build a soduko table 9x9. every square should be checked in its relative colum and row to see its not already used.