Jump to content

Removing Duplicates in random number

- - - - -

  • Please log in to reply
3 replies to this topic

#1
1Maddoc

1Maddoc

    Newbie

  • Members
  • Pip
  • 1 posts
Hi I just started using VB 2008 and I am working with random number.
I got the code below from this site.

Dim random as New Random
dim num as integer
num=random.next(1,21)

My question is...How can I get out the duplicates numbers and replace them with the correct number?

Please help .

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
You'll have to clarify. One of the properties of random numbers is that, given a long enough sequence, you should expect to get duplicates. Given that, what are you trying to do? What is a "correct number"?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Blimp

Blimp

    Programmer

  • Members
  • PipPipPipPip
  • 154 posts
I think he means not having duplicates.. You must understand that as you go down the line, it will become increasingly difficult for the program to find a number that isn't used. You could probably use a For Each statement, but without any actual knowledge of how far into your code you are, we have no way of helping you.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
I figured as much. Usually, I'll do something like use an array or list to store the numbers I want to scramble, and reduce the range of random numbers by one while removing the selected item from the list.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users