Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Randomseed

edited August 2013 in Questions Posts: 577

Hi guys! I've ran into a small problem(Maybe a bug?) with the randomseed, it effects everything in a project, for example, lets say I have a two sprites, and I want the Ipad to randomly choose the same color for both of them, the easiest and only way I can think of doing that would be the randomseed. Then we want it to spawn them both at different random locations, the sad thing is, the randomseed will effect both of these things, not just one. Any help? :)

Comments

  • edited August 2013 Posts: 580

    That behavior is correct. The reason you would want to set randomseed is so you can get reproducible random number generation.

    I'm confused by this:
    "lets say I have a two sprites, and I want the Ipad to randomly choose the same color for both of them"

    How can you force the ipad to randomly generate the exact same color values for separate calls to random()? If you want two sprites to be the same color, but with different positions, couldn't you generate the color variables once and then just set both sprites to use that color, and then generate the positions for each of them separately?

  • dave1707dave1707 Mod
    Posts: 8,192

    @Prynok math.randomseed(value) will create the same sequence of random numbers each time math.random() is called. The purpose of that is to allow you to debug a program that uses random numbers. By using the same value in math.randomseed(), you'll get that same sequence of random numbers over and over again. You can either use a different value or don't use math.randomseed(value), just use math.random() with whatever range you need.

  • Posts: 577

    So how do you suppose I could separate the tint, and the postion, but still keep them random? :/

  • IgnatzIgnatz Mod
    Posts: 5,396

    @Prynok - if you're saying that you want to choose random values for tint and position, but you want those values to be controlled by randomseed so you can guarantee the same random numbers, AND you want a different random see for tint and position, why don't you do it like this?

    math.randomseed(a)
    --choose tint random number
    math.randomseed(b)
    --choose position random numbers

    ie use randomseed twice

  • Posts: 577

    The problem is, for the position, I want it to not have a randomseed at all, is there anyway to do that?

  • Posts: 577

    Is there any fancy thing like the notint thing, but for math?

  • Posts: 1,976

    Just say something like spriteTint = color(math.random(1, 255)). Then you can use that variable whenever you want to tint it and use math.random() for the positions. Then they are placed randomly but with the same tint color. (Use tint(spriteTint))

Sign In or Register to comment.