Necromancing.
The accepted answer will fail if the topic has only one entry, and gebruiker has only one entry.
You need to subtract -1 from row_number:
SELECT
t.id
,g.id AS gebruikerid
FROM
(
SELECT
id
,
(
(ROW_NUMBER() OVER (ORDER BY NEWID() ) -1)
%
(SELECT COUNT(*) FROM gebruiker)
) + 1 AS rn -- number FROM 1 to n
FROM topic
) AS t
INNER JOIN
(
SELECT
id
,ROW_NUMBER() OVER (ORDER BY NEWID() ) AS rn -- sequential number FROM 1 to n
FROM gebruiker
) AS g
ON t.rn = g.rn
ORDER BY t.id
And then, you can update with a CTE:
;WITH CTE AS
(
SELECT
t.id
,t.GebruikerID
,g.id AS gebruikerid
FROM
(
SELECT
id
,GebruikerID
,
(
(ROW_NUMBER() OVER (ORDER BY NEWID() ) -1)
%
(SELECT COUNT(*) FROM gebruiker)
) + 1 AS rn -- number FROM 1 to n
FROM topic
) AS t
INNER JOIN
(
SELECT
id
,ROW_NUMBER() OVER (ORDER BY NEWID() ) AS rn -- sequential number FROM 1 to n
FROM gebruiker
) AS g
ON t.rn = g.rn
)
-- SELECT * FROM CTE
UPDATE CTE SET GebruikerID = gebruikerid