Meta Interview Question

The questions were : write a SV code to get unique random numbers, rand vs randc, write driver code etc.

Interview Answers

Anonymous

Feb 15, 2020

rand , blindly randomizes based on constraints so there is no guarantee that elements would not get repeated before covering all the possible elements. randc guarantees that no elements would be repeated unless all the possible elements have been returned.

1

Anonymous

Feb 15, 2020

int arr[]; int len = 20; // For example arr = new[len]; foreach(arr[i]) arr[i] = i; // assign index to elements so that they are unique arr.shuffle(); // shuffle them to randomize //// Keep shuffling once we used all 20 elements.