title: SQL QUERY: How to assign random different value of column in a table, to differents row in another table?
body: <p>I'm developing a desktop application that works like Risiko!'s game, based on some database procedures.</p>
  
  <p>I need to assign to each player a tot of rows which are not equal to each other assigned to other players.</p>
  
  <p>I've tried for something like this, but doesn't work:</p>
  
  <pre><code> `create or replace PROCEDURE  "giveterritory"
      (idpartita NUMBER,nr_partecipanti number )
     is
  
   begin
  
   DECLARE
  
   CURSOR cur_file IS
  
  SELECT *
  FROM Player
  WHERE idgame = Player.idgame ;
  
  var_cur cur_file%ROWTYPE;
  
  cont number ;
  nr_territories_gioc_prec number ;
  G1_Terr int ;  
  G2_Terr int ;  
  G3_Terr int ;
  G1_ID number;
  G2_ID number;
  G3_ID number;
  begin
  
  cont:=0 ;
  
  for var_cur in cur_file 
  
  loop
  
  cont := cont + 1 ;  
  
      update territory
      set    Player_owner = var_cur.id_Player
      where ROWNUM = MOD( MOD ( number_RANDOM(),42 ) ,ROWNUM );
   G1_Terr := var_cur.number_territories_tot ;   -- mi salvo i territories del primo Player
   G1_ID := var_cur.id_Player ;
   end if ;
     if (cont=2 ) then 
  
  
      update territory
      set    Player_owner = var_cur.id_Player
      where ROWNUM = MOD( MOD ( number_RANDOM(),42 -G1_Terr ) , ROWNUM ) and id_territory NOT IN ( select Player_owner from territory where ;
  
      G2_Terr := var_cur.number_territories_tot  ;    
      end if ;
   if (cont=3 ) then 
  
  
      update territory
      set    Player_owner = var_cur.id_Player
      where ROWNUM &lt;= 42 - G1_Terr - G2_Terr;
      --where ROWNUM &lt;= 42 - var_cur.number_territories_tot * 2 ;
   G3_Terr := var_cur.number_territories_tot  ;   
   end if ;
   end loop;
   end;
  
  end;`
  </code></pre>
  
  <p>number_random code: </p>
  
  <pre><code>        create or replace FUNCTION  "NUMBER_RANDOM"
        return NUMBER
        is
        numbrndm int;
        begin
  
           select dbms_random.value(1,99999999) into numbrndm
          from dual;
     return numbrndm;
     end;
  </code></pre>