title: Randomize my record in ruby on rails
body: <p>I created a quiz and have to randomize the questions to display using <strong>shuffle</strong> but when i call the next function to display next question. the order again shuffled I just want the shuffled order before controller starts and retain that in all the actions for that controller</p>
  
  <pre><code>private
    def shuffle(exam_group_id,student_additional_field_id)
      questions = Question.find(:all, :conditions =&gt; ['exam_group_id=? &amp;&amp; student_additional_field_id=?',exam_group_id,student_additional_field_id]).flatten.shuffle
    end
  </code></pre>
  
  <p>Here i use the function next </p>
  
  <pre><code>class AnswersController &lt; ApplicationController
      def start
          @user = current_user
          @student = Student.find_by_admission_no(@user.username)
          @exam_group = ExamGroup.find_by_id(params[:exam_group_id])
          @answer = Answer.new(params[:ans])
          @module = params[:student_additional_field]
          @questions = shuffle(@exam_group,@module)
          @ques = []
          @questions.each do |a|
            @ques.push a.id unless a.id.nil?
          end
          a = @ques[0]
          @s = 1
          @ans = Question.find_by_id(a)  
          render(:update) do |page|
            page.replace_html 'main', :partial =&gt; 'ans', :object =&gt; @ans
            page.replace_html 'quespan', :partial =&gt; 'ques'
          end
        end
      def next
          @user = current_user
          @student = Student.find_by_admission_no(@user.username)
          @exam_group = ExamGroup.find_by_id(params[:exam_group_id])
          @answer = Answer.new(params[:ans])
          @answer.answer = params[:answer]
          unless params[:answer].nil?
            @answer.visited = 1
          else 
            @answer.visited = 0
          end
          @answer.exam_group_id = @exam_group.id
          @answer.user_id = @user.id
          passed_question = params[:passed_question]
          @answer.questions_id = passed_question
          @question = Question.find_by_id(passed_question)
          @module = Question.find_by_sql ["SELECT student_additional_field_id FROM questions WHERE id=#{passed_question}"]
          student_additional_field_id = @module[0].student_additional_field_id
          @s = 1 
          @questions = shuffle(@exam_group,student_additional_field_id)
          @ques = []
          @questions.each do |a|
            @ques.push a.id unless a.id.nil?
          end
          a = @ques[0] 
          @answer.modules_id = student_additional_field_id
            if params[:answer] == @question.is_answer
              @answer.marks = 1
            else
              @answer.marks = 0
            end
  
          if @answer.save
            @ans = Question.find_by_id(a, :conditions =&gt; [' id not in (?)',answered])
            @s = @s + answered.count
            unless @ans.nil?
              render(:update) do |page|
                page.replace_html 'main', :partial =&gt; 'ans', :object =&gt; @ans
              end
            else
              render(:update) do |page|
                page.replace_html 'main', :partial =&gt; 'ans2'
              end
            end
          end
        end
  </code></pre>
  
  <p>please help me out</p>