Pergunta de entrevista da empresa Meta

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

Respostas da entrevista

Sigiloso

15 de fev. de 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

Sigiloso

15 de fev. de 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.