I am trying to get attempt id before the quiz begins.
I mean i have to get the attempt id in mod/quiz/view.php page
but it actually generates in mod\quiz\startattempt.php.
Is there any way to achieve this?
I am going to throw a dice tomorrow. Can you tell me now what number it will show?
No, you can't (unless you can build a time machine ).
You will have to find a different way to do whatever it is you are trying to do.