Discussions

SmileBASIC Community

Taylormonovae1324

08/17/2016 4:40 PM ·Spoilers

Open Closed

biased randomness

so if you want to generate "random" numbers but want one number to appear more often, you need modular division. say I have 0,1,2 and I want 0 the most. what I do is take rnd(4), which gives me 0,1,2,3. now if I take (rnd(4) mod 3), I get 0,1,2,0. the 0 now shows up twice as much as the others. rest in comments

Advertisement

Comment

This post has no comments.

  • you can stack this for better results. (((rnd(6) mod 5) mod 4) mod 3) yields 4 times as many zeroes as 1s or 2s. if you want the emphasis on 1 or 2 instead, just raise values to 1,2,3 or 2,3,4 and then use if A>2 then A=A-3

    Yeahs0
    Played
  • I have developed a system for controlling distribution ranges through random dice rolls. Easiest to make is a bell curve so the middle value occurs most frequently. I may have to share this.

    Yeahs0
    Played
  • Nice methods! When I need numbers to appear more frequently, I usually just go the easy way and distribute a random number among certain ranges. So it would look something like this... R=RND(100) IF R<20 THEN 'SMTH1 ELSEIF R<50 THEN 'SMTH2 ELSE 'SMTH3 ENDIF

    Yeahs2
    Played
  • Oh! Oh! I know this one Took forever to find it on stackoverflow Mkay So you want a bell curve with 0.5 most often, and near 0 or 1 to be rarer This is how (RND()+RND())/2 for a little bit of focus on 0.5 (RND()+RND()+RND())/3 for more focus on 0.5 (RND()+RND()+RND()+RND())/4 for more focus on 0.5 and near 1 or 0 to be way way more rare ...and so on

    Yeahs0
    Played
  • I meant RNDF() not RND(), RNDF() allows decimal values Anyways here's a demo It features a quick and simple BELL(N) function made to replace the RNDF() function, and it basically allows you to select the amount of focus on 0.5, while it is still completely possible to get a value near 0 or 1, its just extremely rare

    Yeahs1
    Played
  • And here's the output, which as you can see shows that the middle of the screen (0.5) is the most common place for a dot to be, and if you increase the number inside the BELL() function then you can make getting a value near either edge of the screen to be EXTREMELY rare, and we're talking about 1 in a million for BELL(80)

    Yeahs2
    Played
  • Histogram view

    Yeahs2
    Played

Add a Comment

You must sign in to post a comment.

Sign in using a Nintendo Network ID to connect to users around the world by writing posts and comments and by giving Yeahs to other people's posts. You can create a Nintendo Network ID using your Wii U console or your system in the Nintendo 3DS family.

Use of Miiverse Details about Miiverse

Report Violation to Miiverse Administrators

You are about to report a post with content which violates the Miiverse Code of Conduct. This report will be sent to Nintendo's Miiverse administrators and not to the creator of the post.

Violation Type:

Post ID: 3DB-NBL7-EJ9-9E2C-R4F-G8LA

Report Violation to Miiverse Administrators

You cannot report posts made automatically by a software title.

Edit Post

Select an action: