ActiveDen

a perfect random number algorithm?

1234 posts
  • Bought between 50 and 99 items
  • Elite Author
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 50 and 99 users
  • Sold between 50 000 and 100 000 dollars
  • United States
MBMedia says
Can a computer really create a random number? I mean where is it based on?

A random function is not truly random, it’s one of any number of equations that yields numbers that are seemingly random, and is “seeded” with a number of choice. Most languages allow you to seed your random function, and if you use the same seed, the function will give the same results in order every time. Flash automatically seeds it using something that changes regularly (the day and time I assume) and we end up with our random numbers :)

http://pastie.org/393526

The above is a common one ;)

607 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • India
  • Referred between 1 and 9 users
sanju1979 says

Hi! Rahul…

I have done it long time back.. Can guide you for free..if you want source it will cost you USD 125 :)

so here is the logic

create 4 arrays

a1 a2 a3 and a4

in array a1 – push values of 1 digit

in array 2 – push values of 2 digit

in array 3 push values of 3 digit

in array 4 push values of 4 digit

now create an array a5

select 5 values from each array and combine them and push them in array a5

you may decide how many items you want from each array

hope i am clear

regards

sanjeev

2984 posts
  • Community Superstar
  • Has been a member for 5-6 years
  • Won a Competition
  • Sold between 50 000 and 100 000 dollars
  • Bought between 10 and 49 items
  • Referred between 50 and 99 users
  • Europe
+1 more
wickedpixel says

Yo, a random number is a random number! If you alter the logic behind the random function to get more small numbers… you break the randomness…

The probability of getting numbers in the interval 1-99 is equal with the probability of getting numbers from the interval 6001-6099.

my random distribution test. 50 numbers per second, from 0 to 500. simple Math.random() from flash


Sanju.. can you just once post a comment on the forums without adding your fee?

4335 posts
  • Beta Tester
  • Bought between 10 and 49 items
  • Community Moderator
  • Contributed a Blog Post
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
  • Grew a moustache for the Envato Movember competition
  • Has been a member for 4-5 years
+6 more
Reaper-Media moderator says
Can a computer really create a random number? I mean where is it based on?

A random function is not truly random, it’s one of any number of equations that yields numbers that are seemingly random, and is “seeded” with a number of choice. Most languages allow you to seed your random function, and if you use the same seed, the function will give the same results in order every time. Flash automatically seeds it using something that changes regularly (the day and time I assume) and we end up with our random numbers :)

http://pastie.org/393526

The above is a common one ;)
You’re half right: when it doesn’t matter how random a number id, the date/time may be seeded, however linux came up with a truely random number generator which uses thermal noise from a peice of hardware ( the entropy pool ) as a seed basically so a truely random number is created not reliant on any constant / looping variables.

If that makes sense :P

690 posts
  • Bought between 10 and 49 items
  • Canada
  • Exclusive Author
  • Has been a member for 6-7 years
  • Sold between 1 000 and 5 000 dollars
geoken says

people who bought ticket from 1000 to 9999 will have more chance to win.

This makes no sense. If people are buying a single ticket/number than why are you comparing ranges? You’re just taking an arbitrary range (0-999) then taking a different arbitrary range which is ~9x larger (1k-10k) and saying one occurs more frequently.

Any modifications you do to the algorithm will be directly skewing the results towards a range of numbers.

1 post
  • Has been a member for 3-4 years
richardspop says

U can always use probability distribution to create your own random no. set. all u have to do is correct the output so that the mean is toward the the three digit sequence. but this will break the concept of randomness

531 posts
  • Bought between 10 and 49 items
  • Contributed a Blog Post
  • Elite Author
  • Exclusive Author
  • Germany
  • Has been a member for 3-4 years
  • Referred between 100 and 199 users
+1 more
radykal says

Hey

I have a good and easy solution for you. In Actionscript 3 Cookbook is a class, that generates random numbers between two numbers.

import ascb.util.NumberUtilities;
NumberUtilities.random(1, 100);
//generates a random number between 1 and 100

So I optimize this a little bit and you would like to get so many 1 digits number as 4 digits number. So this loop gives 5 numbers of each digit.

import ascb.util.NumberUtilities;

var counter:int = 1;
for(var i:uint = 0; i < 20; ++i)
{        
    if(!(i%5))
    {
        counter *= 10;
    }

    trace(NumberUtilities.random(0.1 * counter, 1 * counter));
}
This is the result, what you get:
7
5
6
10
3
36
68
59
82
24
113
233
842
960
271
7994
3414
6970
2148
6641

You can download the class here.

P.S. When you dont know, how the modulo operator works. There is a new tutorial at the activeden blog, where I explain it clearly.

by
by
by
by
by