1
$\begingroup$

I want to find out a function or algorithm, whichever is suitable, which can provide me a random sequence. Like

Input: 3

Output: {1,2,3} or {1,3,2} or {2,1,3} or {2,3,1} or {3,1,3} or {3,2,1}

Same as if I will enter a number N, output will be a random permutation of the set {1,2,...N}

How can a I write this type of algorithm. Actually I want to find out the logic behind it.

Edit: I don't want to use any buffer to to save anything.

  • 0
    You might get a fine answer here. If not, you could try to migrate the question to http://crypto.stackexchange.com/. Over there they are good at stuff like that.2012-08-29
  • 0
    If you are just looking to get the job done, there should be a pseudorandom number generator in the library of whatever language you're using.2012-08-29
  • 0
    Actually my aim is to find out all the records randomly. I am not talking about any language etc. I want just the logic to retrieve all the records without any repetition, which can be shown by my question.2012-08-29
  • 0
    @Thomas: thanx, I have posted it on crypto.stackexchange.com2012-08-29
  • 0
    Have you looked up random permutation generation on google?2012-08-29
  • 0
    [Cross posted](http://crypto.stackexchange.com/questions/3674/random-sequence-generator-function) on crypto.SE.2012-08-29

2 Answers 2