Algorithm 从Active Directory应用程序模式中随机选择一条记录

Algorithm 从Active Directory应用程序模式中随机选择一条记录,algorithm,directoryservices,Algorithm,Directoryservices,我需要一个例程从ADAM(Active Directory应用程序模式)中随机选择记录。有什么建议可以让我开始这项任务吗?使用带有(objectClass=user)的筛选器,随机选择一个结果可能会起作用。类似于 private static Random rnd = new Random(); private static DirectoryEntry GetRandomUser() { DirectoryEntry luckyGuy; var de = new Direct

我需要一个例程从ADAM(Active Directory应用程序模式)中随机选择记录。有什么建议可以让我开始这项任务吗?

使用带有(objectClass=user)的筛选器,随机选择一个结果可能会起作用。类似于

private static Random rnd = new Random();

private static DirectoryEntry GetRandomUser()
{
    DirectoryEntry luckyGuy;
    var de = new DirectoryEntry(/*conn string*/);
    de.Username = /* your user */;
    de.Password = /* your pass */;

    // error handling and try-catch removed for clarity and brevity
    var s = new DirectorySearcher( de );
    s.Filter = "(objectClass=user)";
    var res = s.FindAll();

    if( res.Count > 0 )
    {
      var idex = rnd.Next(0, res.Count);
      luckyGuy = res[idex].GetDirectoryEntry();
    }

    return luckyGuy;
}
以下是。

使用带有(objectClass=user)的筛选器,随机选择结果可能会起作用。类似于

private static Random rnd = new Random();

private static DirectoryEntry GetRandomUser()
{
    DirectoryEntry luckyGuy;
    var de = new DirectoryEntry(/*conn string*/);
    de.Username = /* your user */;
    de.Password = /* your pass */;

    // error handling and try-catch removed for clarity and brevity
    var s = new DirectorySearcher( de );
    s.Filter = "(objectClass=user)";
    var res = s.FindAll();

    if( res.Count > 0 )
    {
      var idex = rnd.Next(0, res.Count);
      luckyGuy = res[idex].GetDirectoryEntry();
    }

    return luckyGuy;
}

以下是。

您将如何从集合中随机选取结果?您将如何从集合中随机选取结果?