public function randomizequestions($id)
 {
     $test = Test::findorFail($id);
     $qbcontroller = new QuestionBankController();
     $ratings = array_pluck($test->ratings->toArray(), "rating");
     foreach ($test->parts as $key => $part) {
         //$subjectids=$part->subjects;
         $qchapters = $this->getchapterIdsfromSubject($part->subjects);
         foreach ($part->sections as $key => $section) {
             $questiontype = $section->question_type;
             // question type from section
             $totalquestioninsection = count($section->questions);
             // total nos of question in section
             $q = [];
             //all question for particular section from all corresponding chapters/subject/filter['rating',level]
             foreach ($section->questions as $key => $question) {
                 if (count($q) < 1) {
                     // if questions not fetched then fetch first
                     foreach ($qchapters as $key => $qchapter) {
                         $cQuestion = $qbcontroller->getallquestionsbyChapterID($qchapter, $question->level, $questiontype, $ratings);
                         if (count($cQuestion) > 0) {
                             array_push($q, $cQuestion);
                         }
                     }
                     if ($totalquestioninsection > count($q)) {
                         #if nos. of available question less than nos. of required then throw error
                         return \Response::json('Not minimum required questions ', 500);
                     }
                     $q = collect($this->custom_flatten($q))->groupBy('chapter_id');
                 }
                 $t = count($q);
                 $key = $q->keys()->random();
                 //id of random chapters
                 $qq = $q[$key];
                 //questions of random chapter
                 $qqqID = $qq->random();
                 //random question to be pulled
                 $question->data = $qbcontroller->getquestionshbyQuestionId($qqqID['id']);
                 //pick random question->id
                 /* TO BE IMPLEMENTED LATER */
                 if ($t >= $totalquestioninsection) {
                     //$q = chapters that has question available
                     //get 1 question from each chapter
                     //randomly select one chapter => 1 question => remove that chapter from $q
                     // need to get questions from question back as it has to fetch extra data
                     //$key=$keys;//to be pulled
                     $q->pull($key);
                     //pull the chapter so that no repeatation of chapter occurs
                 } else {
                     if ($t < $totalquestioninsection) {
                         //pick $totalquestioninsection nos chapter and then a question
                         # # # # # # # # # THESE ALL REQUIRED */
                         $qqArr = $qq->toArray();
                         $qitbd = array_search($qq->where("id", $qqqID['id'])->first(), $qqArr);
                         //$questionIndexToBeDeleted
                         array_splice($qqArr, $qitbd, 1);
                         $q[$key] = collect($qq);
                     }
                 }
                 $totalquestioninsection--;
                 //decrease the required question in section
             }
         }
     }
     return $test->toJson();
 }