Thread: Iteration?

  1. #1
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128

    Iteration?

    Hey

    Say that I wanted to create a random number on call, is that possible?

    By this I mean that if I need a random number can I call a function without writing the entire, seed .. modulo, etc. ?

    Secondly can you iterate this function and set each iteration to a varible?

    E.g.

    I have a random number code,

    But I want to set 10 varibles with random numbers?

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    The simple way is to write a wrapper function for the standard random number functions, and have that function do the seeding only the first time it is called. You can also do a similar thing for any third-party pseudo-random number generators.

    You don't need to iterate a function: simply call it multiple times in a loop, and assign its return value to some variable.

  3. #3
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    I see, well Ill research into it and try and find how to do it as im pretty basic atm.

    Thanks for the heads up.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MPI - linear pipeline solution for jacobi iteration
    By eclipt in forum C++ Programming
    Replies: 1
    Last Post: 05-03-2006, 05:25 AM
  2. recursivity & iteration
    By Marlon in forum C++ Programming
    Replies: 2
    Last Post: 06-14-2005, 01:58 PM
  3. Replies: 3
    Last Post: 12-22-2004, 07:29 PM
  4. The "continue" statement in JAVA
    By Hexxx in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 02-26-2004, 06:19 PM
  5. Iteration help please
    By incognito in forum C++ Programming
    Replies: 3
    Last Post: 12-09-2001, 07:37 AM